-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLLM_Reason.py
More file actions
59 lines (46 loc) · 1.75 KB
/
Copy pathLLM_Reason.py
File metadata and controls
59 lines (46 loc) · 1.75 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
import os
from groq import Groq
# Initialize the Groq client with the API key from the environment variable
client = Groq(
api_key=os.environ.get("GROQ_API_KEY"),
)
def analyze_data(data: str, model: str = "llama3-8b-8192") -> str:
"""
Function to send data to Groq and request a detailed analysis.
Args:
- data (str): The data to be analyzed (could be text, tables, or JSON).
- model (str): The model to be used for the analysis (default is "llama3-8b-8192").
Returns:
- str: The detailed analysis from Groq.
"""
# Construct the prompt to ask for a detailed analysis
prompt = f"""
Here is a dataset:
{data}
Please provide a detailed analysis in rich text format without the use of stars(*), of the data, including trends, patterns, and any insights you can derive from it.
"""
# Send the prompt to Groq and request a completion for the analysis
response = client.chat.completions.create(
messages=[
{"role": "user", "content": prompt},
],
model=model, # Using the provided model
)
# Return the detailed analysis from the response
return response.choices[0].message.content
# Example usage
if __name__ == "__main__":
# Sample data (could be any dataset or text)
data = """
| Name | Age | Occupation | Income |
|----------|-----|-----------------|---------|
| Alice | 30 | Software Engineer | 100000 |
| Bob | 25 | Data Scientist | 95000 |
| Charlie | 35 | Manager | 120000 |
| David | 28 | Designer | 85000 |
"""
# Call the function to get detailed analysis
analysis = analyze_data(data)
# Print the analysis
print("Detailed Analysis:")
print(analysis)