Spaces:
Sleeping
Sleeping
zasharepw77
commited on
Commit
·
ca94485
1
Parent(s):
6255a71
My model call
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from smolagents import ToolCallingAgent, CodeAgent, DuckDuckGoSearchTool, LiteLLMModel
|
| 2 |
import os
|
|
|
|
| 3 |
#import litellm
|
| 4 |
#litellm._turn_on_debug() # Enable debugging for litellm
|
| 5 |
|
|
@@ -14,10 +15,34 @@ model = LiteLLMModel(
|
|
| 14 |
api_base="https://api.sambanova.ai/v1", # Specify the base URL for Sambanova, as in your working requests example
|
| 15 |
)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Create the agent
|
| 18 |
agent = ToolCallingAgent(
|
| 19 |
tools=[DuckDuckGoSearchTool()],
|
| 20 |
-
model=
|
| 21 |
)
|
| 22 |
|
| 23 |
# Когда запуск идет через streamlingt то ответы переводятс в json автоматом
|
|
|
|
| 1 |
from smolagents import ToolCallingAgent, CodeAgent, DuckDuckGoSearchTool, LiteLLMModel
|
| 2 |
import os
|
| 3 |
+
import requests
|
| 4 |
#import litellm
|
| 5 |
#litellm._turn_on_debug() # Enable debugging for litellm
|
| 6 |
|
|
|
|
| 15 |
api_base="https://api.sambanova.ai/v1", # Specify the base URL for Sambanova, as in your working requests example
|
| 16 |
)
|
| 17 |
|
| 18 |
+
# Создание модели с обработкой лимитов
|
| 19 |
+
def model_call(query):
|
| 20 |
+
try:
|
| 21 |
+
url = "https://api.sambanova.ai/v1/chat/completions" # Проверьте, что это правильная конечная точка
|
| 22 |
+
headers = {
|
| 23 |
+
"Authorization": f"Bearer {os.getenv('sambanova_token')}",
|
| 24 |
+
"Content-Type": "application/json"
|
| 25 |
+
}
|
| 26 |
+
data = {
|
| 27 |
+
"model": "Qwen2.5-Coder-32B-Instruct",
|
| 28 |
+
"messages": [{"role": "user", "content": "Раскажи о себе."}],
|
| 29 |
+
"max_tokens": 2096
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
response = requests.post(url, headers=headers, json=data)
|
| 33 |
+
print(response.status_code)
|
| 34 |
+
print(response.text)
|
| 35 |
+
return response.choices[0].message.content
|
| 36 |
+
except openai.RateLimitError:
|
| 37 |
+
time.sleep(60) # Ждем 60 секунд перед повторной попыткой
|
| 38 |
+
return model_call(query) # Рекурсивный вызов
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"An unexpected error occurred: {str(e)}"
|
| 41 |
+
|
| 42 |
# Create the agent
|
| 43 |
agent = ToolCallingAgent(
|
| 44 |
tools=[DuckDuckGoSearchTool()],
|
| 45 |
+
model=model_call
|
| 46 |
)
|
| 47 |
|
| 48 |
# Когда запуск идет через streamlingt то ответы переводятс в json автоматом
|