-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse_case_generator.py
More file actions
53 lines (40 loc) · 2.1 KB
/
use_case_generator.py
File metadata and controls
53 lines (40 loc) · 2.1 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
import os
import cohere
import database
# Set your Cohere API key
cohere_api_key = os.getenv("COHERE_API_KEY")
# Initialize the Cohere client
client = cohere.Client(cohere_api_key)
def generate_use_case(company_info):
# Prepare the prompt using all available company information
# Prepare a concise prompt focusing on key elements only
prompt = f"Generate a structured, concise AI use case for '{company_info['company_name']}', an automotive company. Focus on the main objectives, benefits, and implementation details. Try to include everything under 90 to 100 words only."
# # Add company introduction if available
# if 'intro' in company_info:
# prompt += f"\n\nCompany Introduction: {company_info['intro']}"
# Add a single line for the task description
prompt += "\n\nTask: Describe a specific AI use case with key details, avoiding repetition. And also provide me a small response within 50 words."
# Generate the AI-based use case using Cohere API
response = client.generate(
model="command-xlarge-nightly", # Adjust to any Cohere model available in your account
prompt=prompt,
max_tokens=300, # Adjust max tokens as necessary
temperature=0.4 # Adjust temperature for creativity level, if needed
)
use_case_text = response.generations[0].text.strip()
# Generate main theme specifically for dataset search
main_theme_response = client.generate(
model="command-xlarge-nightly", # Ensure the model name matches
prompt=f"Extract a concise heading or topic name from the following text for dataset search: {use_case_text}. Provide only the main topic name without additional context or phrases.",
max_tokens=50, # Limit tokens since we want a concise theme
temperature=0.3
)
main_theme = main_theme_response.generations[0].text.strip()
# Prepare and save the use case in the database
use_case = {
"company": company_info["company_name"],
"use_case": use_case_text,
"main_theme": main_theme
}
database.insert_use_case(use_case)
return use_case