-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm_helper.py
More file actions
25 lines (22 loc) · 739 Bytes
/
Copy pathllm_helper.py
File metadata and controls
25 lines (22 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# llm_helper.py
import os
import openai
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_disease_info(disease_name: str) -> str:
"""
Generate information and cure for a given plant disease using OpenAI GPT.
"""
prompt = (
f"Provide a short description and simple cure or treatment for the plant disease: {disease_name}."
)
try:
response = openai.ChatCompletion.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}],
max_tokens=150
)
return response.choices[0].message.content.strip()
except Exception as e:
return f"Error generating disease info: {e}"