Ubik80 commited on
Commit
822a378
·
verified ·
1 Parent(s): 94aca96

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +3 -9
tools.py CHANGED
@@ -1,33 +1,27 @@
1
- # tools.py
2
  import os
3
  import openai
4
  from smolagents.tools import Tool
5
 
6
- # Carichiamo la tua chiave
7
  openai.api_key = os.getenv("OPENAI_API_KEY")
8
 
9
  SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
10
  FINAL ANSWER: [YOUR FINAL ANSWER].
11
-
12
  YOUR FINAL ANSWER should be:
13
  - a number OR as few words as possible OR a comma separated list of numbers and/or strings.
14
  - If you are asked for a number, don't use commas, symbols or units (e.g. %, $, km) unless explicitly asked.
15
  - If you are asked for a string, don't use articles ("a", "the"), abbreviations (e.g. "NYC"), or extra words; write digits in plain text unless specified otherwise.
16
  - If you are asked for a comma separated list, apply the above rules to each element.
17
-
18
  Examples:
19
  Q: How many legs does a spider have?
20
  Thought: It's basic biology.
21
  FINAL ANSWER: 8
22
-
23
  Q: What are the primary colors in light?
24
  Thought: Physics concept.
25
  FINAL ANSWER: red, green, blue
26
-
27
  Q: Who won the Best Picture Oscar in 1994?
28
  Thought: Film history.
29
  FINAL ANSWER: Forrest Gump
30
-
31
  Now it's your turn.
32
  """
33
 
@@ -42,7 +36,7 @@ class AnswerTool(Tool):
42
  {"role": "system", "content": SYSTEM_PROMPT},
43
  {"role": "user", "content": question},
44
  ]
45
- # qui usiamo la nuova API v1
46
  resp = openai.chat.completions.create(
47
  model="gpt-4o",
48
  messages=messages,
@@ -52,4 +46,4 @@ class AnswerTool(Tool):
52
  text = resp.choices[0].message.content.strip()
53
  if "FINAL ANSWER:" in text:
54
  return text.split("FINAL ANSWER:")[-1].strip()
55
- return text
 
 
1
  import os
2
  import openai
3
  from smolagents.tools import Tool
4
 
5
+ # Load your OpenAI API key
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
  SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
9
  FINAL ANSWER: [YOUR FINAL ANSWER].
 
10
  YOUR FINAL ANSWER should be:
11
  - a number OR as few words as possible OR a comma separated list of numbers and/or strings.
12
  - If you are asked for a number, don't use commas, symbols or units (e.g. %, $, km) unless explicitly asked.
13
  - If you are asked for a string, don't use articles ("a", "the"), abbreviations (e.g. "NYC"), or extra words; write digits in plain text unless specified otherwise.
14
  - If you are asked for a comma separated list, apply the above rules to each element.
 
15
  Examples:
16
  Q: How many legs does a spider have?
17
  Thought: It's basic biology.
18
  FINAL ANSWER: 8
 
19
  Q: What are the primary colors in light?
20
  Thought: Physics concept.
21
  FINAL ANSWER: red, green, blue
 
22
  Q: Who won the Best Picture Oscar in 1994?
23
  Thought: Film history.
24
  FINAL ANSWER: Forrest Gump
 
25
  Now it's your turn.
26
  """
27
 
 
36
  {"role": "system", "content": SYSTEM_PROMPT},
37
  {"role": "user", "content": question},
38
  ]
39
+ # Use the v1 OpenAI API with GPT-4o
40
  resp = openai.chat.completions.create(
41
  model="gpt-4o",
42
  messages=messages,
 
46
  text = resp.choices[0].message.content.strip()
47
  if "FINAL ANSWER:" in text:
48
  return text.split("FINAL ANSWER:")[-1].strip()
49
+ return text