Update example/vllm_v2_extraction_agent.py
Browse files
example/vllm_v2_extraction_agent.py
CHANGED
|
@@ -10,53 +10,53 @@ EXAMPLE OUTPUT:
|
|
| 10 |
|
| 11 |
What is the current population for the city where Einstein was born?
|
| 12 |
|
| 13 |
-
|
| 14 |
----------------------------------------
|
| 15 |
|
| 16 |
Executing: fetch_wiki_content
|
| 17 |
Arguments: {'title': 'Albert Einstein'}
|
| 18 |
|
| 19 |
-
|
| 20 |
----------------------------------------
|
| 21 |
|
| 22 |
Executing: deliver_answer
|
| 23 |
Arguments: {'fields': ['Ulm, German Empire']}
|
| 24 |
ANSWER FROM THE ASSISTANT: ['Ulm, German Empire']
|
| 25 |
|
| 26 |
-
|
| 27 |
----------------------------------------
|
| 28 |
|
| 29 |
Executing: fetch_wiki_content
|
| 30 |
Arguments: {'title': 'Ulm'}
|
| 31 |
|
| 32 |
-
|
| 33 |
----------------------------------------
|
| 34 |
|
| 35 |
Executing: deliver_answer
|
| 36 |
Arguments: {'fields': ['128,928']}
|
| 37 |
ANSWER FROM THE ASSISTANT: ['128,928']
|
| 38 |
|
| 39 |
-
|
| 40 |
----------------------------------------
|
| 41 |
Extraction Complete
|
| 42 |
|
| 43 |
|
| 44 |
Why was Einstein famous?
|
| 45 |
|
| 46 |
-
|
| 47 |
----------------------------------------
|
| 48 |
|
| 49 |
Executing: fetch_wiki_content
|
| 50 |
Arguments: {'title': 'Albert Einstein'}
|
| 51 |
|
| 52 |
-
|
| 53 |
----------------------------------------
|
| 54 |
|
| 55 |
Executing: deliver_answer
|
| 56 |
Arguments: {'fields': ['Best known for developing the theory of relativity, Einstein also made important contributions to quantum mechanics.', 'His mass–energy equivalence formula E = mc2, which arises from special relativity, has been called "the world\'s most famous equation."', 'He received the 1921 Nobel Prize in Physics.']}
|
| 57 |
ANSWER FROM THE ASSISTANT: ['Best known for developing the theory of relativity, Einstein also made important contributions to quantum mechanics.', 'His mass–energy equivalence formula E = mc2, which arises from special relativity, has been called "the world\'s most famous equation."', 'He received the 1921 Nobel Prize in Physics.']
|
| 58 |
|
| 59 |
-
|
| 60 |
----------------------------------------
|
| 61 |
Extraction Complete
|
| 62 |
"""
|
|
@@ -67,7 +67,7 @@ class WikiConfig:
|
|
| 67 |
api_key: str = "sk-123"
|
| 68 |
api_base: str = "{info}/v1"
|
| 69 |
model: Optional[str] = None
|
| 70 |
-
|
| 71 |
wikipedia_base_url: str = "https://en.wikipedia.org/wiki/"
|
| 72 |
|
| 73 |
class WikiTools:
|
|
@@ -239,8 +239,8 @@ class WikiExtractionAgent:
|
|
| 239 |
|
| 240 |
all_results = []
|
| 241 |
|
| 242 |
-
for
|
| 243 |
-
print(f"\
|
| 244 |
print("-" * 40)
|
| 245 |
|
| 246 |
response = self.client.chat.completions.create(
|
|
@@ -273,11 +273,17 @@ def main():
|
|
| 273 |
agent = WikiExtractionAgent(config)
|
| 274 |
|
| 275 |
# Multi-step query example
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
results = agent.extract_information(
|
| 277 |
query="""What is the current population for the city where Einstein was born?"""
|
| 278 |
)
|
| 279 |
-
|
| 280 |
# Single query example
|
|
|
|
|
|
|
| 281 |
results = agent.extract_information(
|
| 282 |
query="Why was Einstein famous?"
|
| 283 |
)
|
|
|
|
| 10 |
|
| 11 |
What is the current population for the city where Einstein was born?
|
| 12 |
|
| 13 |
+
Step 1
|
| 14 |
----------------------------------------
|
| 15 |
|
| 16 |
Executing: fetch_wiki_content
|
| 17 |
Arguments: {'title': 'Albert Einstein'}
|
| 18 |
|
| 19 |
+
Step 2
|
| 20 |
----------------------------------------
|
| 21 |
|
| 22 |
Executing: deliver_answer
|
| 23 |
Arguments: {'fields': ['Ulm, German Empire']}
|
| 24 |
ANSWER FROM THE ASSISTANT: ['Ulm, German Empire']
|
| 25 |
|
| 26 |
+
Step 3
|
| 27 |
----------------------------------------
|
| 28 |
|
| 29 |
Executing: fetch_wiki_content
|
| 30 |
Arguments: {'title': 'Ulm'}
|
| 31 |
|
| 32 |
+
Step 4
|
| 33 |
----------------------------------------
|
| 34 |
|
| 35 |
Executing: deliver_answer
|
| 36 |
Arguments: {'fields': ['128,928']}
|
| 37 |
ANSWER FROM THE ASSISTANT: ['128,928']
|
| 38 |
|
| 39 |
+
Step 5
|
| 40 |
----------------------------------------
|
| 41 |
Extraction Complete
|
| 42 |
|
| 43 |
|
| 44 |
Why was Einstein famous?
|
| 45 |
|
| 46 |
+
Step 1
|
| 47 |
----------------------------------------
|
| 48 |
|
| 49 |
Executing: fetch_wiki_content
|
| 50 |
Arguments: {'title': 'Albert Einstein'}
|
| 51 |
|
| 52 |
+
Step 2
|
| 53 |
----------------------------------------
|
| 54 |
|
| 55 |
Executing: deliver_answer
|
| 56 |
Arguments: {'fields': ['Best known for developing the theory of relativity, Einstein also made important contributions to quantum mechanics.', 'His mass–energy equivalence formula E = mc2, which arises from special relativity, has been called "the world\'s most famous equation."', 'He received the 1921 Nobel Prize in Physics.']}
|
| 57 |
ANSWER FROM THE ASSISTANT: ['Best known for developing the theory of relativity, Einstein also made important contributions to quantum mechanics.', 'His mass–energy equivalence formula E = mc2, which arises from special relativity, has been called "the world\'s most famous equation."', 'He received the 1921 Nobel Prize in Physics.']
|
| 58 |
|
| 59 |
+
Step 3
|
| 60 |
----------------------------------------
|
| 61 |
Extraction Complete
|
| 62 |
"""
|
|
|
|
| 67 |
api_key: str = "sk-123"
|
| 68 |
api_base: str = "{info}/v1"
|
| 69 |
model: Optional[str] = None
|
| 70 |
+
max_steps: int = 5
|
| 71 |
wikipedia_base_url: str = "https://en.wikipedia.org/wiki/"
|
| 72 |
|
| 73 |
class WikiTools:
|
|
|
|
| 239 |
|
| 240 |
all_results = []
|
| 241 |
|
| 242 |
+
for step in range(self.config.max_steps):
|
| 243 |
+
print(f"\nStep {step + 1}")
|
| 244 |
print("-" * 40)
|
| 245 |
|
| 246 |
response = self.client.chat.completions.create(
|
|
|
|
| 273 |
agent = WikiExtractionAgent(config)
|
| 274 |
|
| 275 |
# Multi-step query example
|
| 276 |
+
# The model should first issue a call to wikipedia for Einstein, extract the part from the document about where he was born
|
| 277 |
+
# and use the value from that extraction (which could contain the city name) to call another wikipedia article for the city
|
| 278 |
+
# and pull the population from it.
|
| 279 |
+
# See lines 11 to 41 for the full trace of this actual query that Athene-V2-Agent issues.
|
| 280 |
results = agent.extract_information(
|
| 281 |
query="""What is the current population for the city where Einstein was born?"""
|
| 282 |
)
|
| 283 |
+
|
| 284 |
# Single query example
|
| 285 |
+
# Here, the model should just issue a call to Einstein's wikipedia page, and extract the parts regarding his
|
| 286 |
+
# accomplishment.
|
| 287 |
results = agent.extract_information(
|
| 288 |
query="Why was Einstein famous?"
|
| 289 |
)
|