apple muncy commited on
Commit
d82307d
·
1 Parent(s): b5ed022

move to grok-beta

Browse files

Signed-off-by: apple muncy <[email protected]>

Files changed (1) hide show
  1. app.py +47 -5
app.py CHANGED
@@ -1,10 +1,11 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
 
6
  from tools.final_answer import FinalAnswerTool
7
- from tools.web_search import DuckDuckGoSearchTool
8
  from tools.visit_webpage import VisitWebpageTool
9
 
10
 
@@ -38,12 +39,12 @@ def get_current_time_in_timezone(timezone: str) -> str:
38
 
39
 
40
  final_answer = FinalAnswerTool()
41
- web_search = DuckDuckGoSearchTool()
42
  visit_webpage = VisitWebpageTool()
43
 
44
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
45
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
46
 
 
47
  model = HfApiModel(
48
  max_tokens=8384,
49
  temperature=0.5,
@@ -52,6 +53,46 @@ model = HfApiModel(
52
  custom_role_conversions=None,
53
 
54
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
 
57
  # Import tool from Hub
@@ -62,7 +103,7 @@ with open("prompts.yaml", 'r') as stream:
62
 
63
  agent = CodeAgent(
64
  model=model,
65
- tools=[final_answer, web_search, visit_webpage ], ## add your tools here (don't remove final answer)
66
  max_steps=6,
67
  verbosity_level=1,
68
  grammar=None,
@@ -71,7 +112,8 @@ agent = CodeAgent(
71
  description=None,
72
  prompt_templates=prompt_templates,
73
  add_base_tools=True,
 
74
  )
75
 
76
 
77
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, OpenAIServerModel, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
+ import os
7
+ import json
8
  from tools.final_answer import FinalAnswerTool
 
9
  from tools.visit_webpage import VisitWebpageTool
10
 
11
 
 
39
 
40
 
41
  final_answer = FinalAnswerTool()
 
42
  visit_webpage = VisitWebpageTool()
43
 
44
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
45
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
46
 
47
+ """
48
  model = HfApiModel(
49
  max_tokens=8384,
50
  temperature=0.5,
 
53
  custom_role_conversions=None,
54
 
55
  )
56
+ """
57
+ # Initialize the model
58
+ model = OpenAIServerModel(
59
+ model_id="grok-beta",
60
+ api_base="https://api.x.ai/v1", # Correct base URL
61
+ api_key=os.environ.get("XAI_API_KEY", "your-api-key-here"),
62
+ )
63
+
64
+
65
+ @tool
66
+ def call_grok_api(query: str) -> str:
67
+ """Calls Gork's API with a JSON-encoded query string and returns the response.
68
+
69
+ Args:
70
+ query (str): A string representing the query to be JSON-encoded and sent to Gork's API.
71
+
72
+ Returns:
73
+ str: A string containing the response from Gork's API, or an error message if the request fails.
74
+ """
75
+ try:
76
+ # Prepare JSON-encoded payload
77
+ payload = json.dumps({
78
+ "model": "grok-beta", # Use available model, e.g., grok-beta
79
+ "messages": [{"role": "user", "content": query}],
80
+ "stream": False
81
+ })
82
+ # Make API request
83
+ api_key = os.environ.get("XAI_API_KEY", "your-api-key-here")
84
+ response = requests.post(
85
+ "https://api.x.ai/v1/chat/completions", # Correct xAI API endpoint
86
+ headers={
87
+ "Authorization": f"Bearer {api_key}",
88
+ "Content-Type": "application/json"
89
+ },
90
+ data=payload
91
+ )
92
+ response.raise_for_status()
93
+ return response.json()["choices"][0]["message"]["content"]
94
+ except requests.exceptions.RequestException as e:
95
+ return f"Error calling xAI API: {str(e)}"
96
 
97
 
98
  # Import tool from Hub
 
103
 
104
  agent = CodeAgent(
105
  model=model,
106
+ tools=[call_grok_api, final_answer, visit_webpage ], ## add your tools here (don't remove final answer)
107
  max_steps=6,
108
  verbosity_level=1,
109
  grammar=None,
 
112
  description=None,
113
  prompt_templates=prompt_templates,
114
  add_base_tools=True,
115
+ executor_type="local",
116
  )
117
 
118
 
119
+ GradioUI(agent).launch()