-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsource.py
More file actions
78 lines (69 loc) · 3.33 KB
/
source.py
File metadata and controls
78 lines (69 loc) · 3.33 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
########################################################################
# AN OPEN/GROQ AI CLI INTEGRATION MY NWALI UGONNA EMMANUEL
# GITHUB: https://github.com/Tigo-cmd/TigoAi
# All contributions are welcome!!!
# yea lets do some coding!!!!!!!!!!!!
#########################################################################
"""Source classes to handle all GroqAPI functionalities and trained models
BY Nwali Ugonna Emmanuel
"""
from __future__ import annotations
from groq import Groq
import subprocess
import os
import requests
from dotenv import load_dotenv
class TigoGroq:
"""this handles Api tokens and requests
this class clones the GROQ init function and re-initializes the arguments
so that when the class is called it set every functionality needed for the model to run
"""
client = None
_Apikey = os.getenv("GROQ_API_KEY")
context: list[dict[str, str]] = [
{"role": "system", "content": "You are an expert plant disease assistant specialized in diagnosing and providing solutions for tomato plant diseases and very concise in your response. "
"Your goal is to help users identify and manage tomato plant health issues based on their queries."
"When a user asks a question, provide clear and concise answers. If they ask about specific symptoms (e.g., yellowing leaves, black spots, wilting), explain the possible diseases, causes, and recommended treatments. If the user is unsure about the issue, guide them with follow-up questions to narrow down the problem."
"Additionally, if a user mentions uploading an image, encourage them to use the upload feature and let them know you'll analyze it. Always provide practical advice, such as natural remedies, chemical treatments, and prevention tips.Maintain a friendly and professional tone, and keep responses simple and easy to understand for farmers and plant growers. If a user asks about other plants, gently redirect them to focus on tomatoes."}
]
def __init__(
self,
) -> None:
"""Constructor initialized at first call"""
if self._Apikey is None:
"""
checks if the apikey is present in the environment variable
else loads from env file using python-loadenv
"""
load_dotenv()
self.client = Groq()
# def get_context(self, context: str):
# """
# :param context: tracks conversations and context with users
# :return: nothing
# """
# pass
async def get_response_from_ai(self, message: str):
"""returns response from the AI and messages to print to standard output"""
self.context.append({"role": "user", "content": message})
completion = self.client.chat.completions.create(
model="llama3-70b-8192",
messages=self.context,
temperature=1,
max_tokens=1024,
top_p=1,
stream=True,
stop=None,
)
reply: str = ""
for chunk in completion:
reply += chunk.choices[0].delta.content or ""
self.context.append({"role": "assistant", "content": reply})
return reply
# def store_retrive_context(self, filename: str):
# """
# :param filename:
# :return:
# """
# pass