Skip to content

Commit f37dd9e

Browse files
committed
switch from autogen to plain openai
1 parent 6ef1589 commit f37dd9e

File tree

4 files changed

+29
-47
lines changed

4 files changed

+29
-47
lines changed

.env

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
HOSTING_CHECK_BASE_URL=http://127.0.0.1:8000
12
LLM_LOCAL_BASE_URL=http://xinference:9997/v1
23
LLM_MODEL_NAME=google/gemma-2-27b-it
34
OLLAMA_BASE_URL=http://ollama:11434
4-
HOSTING_CHECK_BASE_URL=http://127.0.0.1:8000
5-
SEARCH_BASE_URL=https://s.jina.ai
5+
OPENAI_API_KEY=sk-proj-aaaaaaaaaaaaaaaaa
6+
OPENAI_BASE_URL=http://localhost:8000/v1
67
RAG_MODEL_DEPLOY=local
8+
SEARCH_BASE_URL=https://s.jina.ai

requirements.local.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ llama-index
44
llama-index-embeddings-huggingface
55
llama-index-embeddings-ollama
66
llama-index-postprocessor-jinaai-rerank
7-
pyautogen
7+
openai
88
uvicorn

requirements.remote.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ fastapi
33
llama-index
44
llama-index-embeddings-ollama
55
llama-index-postprocessor-jinaai-rerank
6-
pyautogen
6+
openai
77
uvicorn

src/llm.py

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import os
2-
from autogen import AssistantAgent
2+
from openai import OpenAI
33
import logging
44

55
import utils
66

7-
logger = logging.getLogger(__name__)
8-
97
"""
108
About models:
119
- Gemma 2 does not support system rule
12-
13-
config_list:
14-
- {"price": [prompt_price_per_1k, completion_token_price_per_1k]}
15-
16-
Todo:
17-
- With xinference + Gemma 2 + AutoGen, why 'system message' does not work well
1810
"""
11+
1912
LLM_MODEL_NAME = os.environ.get("LLM_MODEL_NAME") or "google/gemma-2-27b-it"
20-
config_list_local = [
21-
# set prices, otherwise there will be warnings
22-
{"model": LLM_MODEL_NAME, "base_url": os.environ.get("OLLAMA_BASE_URL") + "/v1", "tags": ["gemma", "local"], "price": [0, 0]},
23-
]
2413

25-
llm_config = {"config_list": config_list_local}
14+
llm_client = OpenAI(
15+
base_url=os.environ.get("OPENAI_BASE_URL"),
16+
api_key="token",
17+
)
18+
19+
def get_llm_reply(prompt):
20+
completion = llm_client.chat.completions.create(
21+
model=LLM_MODEL_NAME,
22+
messages=[
23+
{"role": "user", "content": prompt}
24+
]
25+
)
26+
return completion.choices[0].message.content
2627

2728
"""
2829
Get list of statements from input.
@@ -33,21 +34,14 @@ def get_statements(input):
3334
Extract key facts from the given content.
3435
Provide a list of the facts in array format as response only.'''
3536

36-
statement_extract_agent = AssistantAgent(
37-
name="statement_extract_agent",
38-
system_message='',
39-
llm_config=llm_config,
40-
human_input_mode="NEVER",
41-
)
42-
43-
content = f'''{system_message}
37+
prompt = f'''{system_message}
4438
```
4539
Content:
4640
{input}
4741
```'''
4842

49-
reply = statement_extract_agent.generate_reply(messages=[{"content": content, "role": "user"}])
50-
logger.debug(f"get_statements LLM reply: {reply}")
43+
reply = get_llm_reply(prompt)
44+
logging.debug(f"get_statements LLM reply: {reply}")
5145
return utils.llm2list(reply)
5246

5347
"""
@@ -59,19 +53,12 @@ def get_search_keywords(statement):
5953
Generate search keyword used for fact check on the given statement.
6054
Include only the keyword in your response.'''
6155

62-
search_keywords_agent = AssistantAgent(
63-
name="search_keywords_agent",
64-
system_message='',
65-
llm_config=llm_config,
66-
human_input_mode="NEVER",
67-
)
68-
69-
content = f'''{system_message}
56+
prompt = f'''{system_message}
7057
```
7158
Statement:
7259
{statement}
7360
```'''
74-
reply = search_keywords_agent.generate_reply(messages=[{"content": content, "role": "user"}])
61+
reply = get_llm_reply(prompt)
7562
return reply.strip()
7663

7764
def get_verdict(statement, contexts):
@@ -85,14 +72,7 @@ def get_verdict(statement, contexts):
8572
Be thorough in your explanations, avoiding any duplication of information.
8673
Provide the response as JSON with the structure:{verdict, reason}'''
8774

88-
fact_check_agent = AssistantAgent(
89-
name="fact_check_agent",
90-
system_message='',
91-
llm_config=llm_config,
92-
human_input_mode="NEVER",
93-
)
94-
95-
content = f'''{system_message}
75+
prompt = f'''{system_message}
9676
```
9777
Statement:
9878
{statement}
@@ -103,13 +83,13 @@ def get_verdict(statement, contexts):
10383
_text = node.get('text')
10484
if not _text:
10585
continue
106-
content = f"""{content}
86+
prompt = f"""{prompt}
10787
```
10888
Context {ind + 1}:
10989
{_text}
11090
```"""
11191

112-
reply = fact_check_agent.generate_reply(messages=[{"content": content, "role": "user"}])
92+
reply = get_llm_reply(prompt)
11393
verdict = utils.llm2json(reply)
11494
if verdict:
11595
verdict['statement'] = statement

0 commit comments

Comments
 (0)