Skip to content

Commit 2d0413e

Browse files
committed
fix exception when some content is inappropriate
1 parent d965845 commit 2d0413e

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

event_analysis.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,24 @@ def _zero_shot(prompt: str) -> str:
3434
Core LLM call function to summarize repository topics using a zero-shot prompt.
3535
Returns a direct text summary.
3636
"""
37-
client = openai.OpenAI(
38-
api_key=os.getenv("OPENAI_API_KEY"),
39-
base_url=os.getenv("OPENAI_BASE_URL"),
40-
)
41-
42-
chat_completion = client.chat.completions.create(
43-
messages=[
44-
{
45-
'role': 'user',
46-
'content': prompt,
47-
}
48-
],
49-
model=os.getenv("MODEL_NAME", "qwen-plus"),
50-
)
51-
52-
summary = chat_completion.choices[0].message.content
53-
return summary.strip() if summary else UNKNOWN_SUMMARY
37+
try:
38+
client = openai.OpenAI(
39+
api_key=os.getenv("OPENAI_API_KEY"),
40+
base_url=os.getenv("OPENAI_BASE_URL"),
41+
)
42+
chat_completion = client.chat.completions.create(
43+
messages=[
44+
{
45+
'role': 'user',
46+
'content': prompt,
47+
}
48+
],
49+
model=os.getenv("MODEL_NAME", "qwen-plus"),
50+
)
51+
content = chat_completion.choices[0].message.content
52+
return content.strip() if content else UNKNOWN_SUMMARY
53+
except Exception:
54+
return UNKNOWN_SUMMARY
5455

5556
def summarize_repos_for_working(repos: List[Dict[str, str]]) -> str:
5657
"""

0 commit comments

Comments
 (0)