MCPcopy
hub / github.com/build-with-groq/g1 / make_api_call

Function make_api_call

g1.py:8–38  ·  view source on GitHub ↗
(messages, max_tokens, is_final_answer=False, custom_client=None)

Source from the content-addressed store, hash-verified

6client = groq.Groq()
7
8def make_api_call(messages, max_tokens, is_final_answer=False, custom_client=None):
9 global client
10 if custom_client != None:
11 client = custom_client
12
13 for attempt in range(3):
14 try:
15 if is_final_answer:
16 response = client.chat.completions.create(
17 model="llama-3.3-70b-versatile",
18 messages=messages,
19 max_tokens=max_tokens,
20 temperature=0.2,
21 )
22 return response.choices[0].message.content
23 else:
24 response = client.chat.completions.create(
25 model="llama-3.3-70b-versatile",
26 messages=messages,
27 max_tokens=max_tokens,
28 temperature=0.2,
29 response_format={"type": "json_object"}
30 )
31 return json.loads(response.choices[0].message.content)
32 except Exception as e:
33 if attempt == 2:
34 if is_final_answer:
35 return {"title": "Error", "content": f"Failed to generate final answer after 3 attempts. Error: {str(e)}"}
36 else:
37 return {"title": "Error", "content": f"Failed to generate step after 3 attempts. Error: {str(e)}", "next_action": "final_answer"}
38 time.sleep(1) # Wait for 1 second before retrying
39
40def generate_response(prompt, custom_client=None):
41 messages = [

Callers 1

generate_responseFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected