zhaoliangvaio commited on
Commit
5a97822
·
verified ·
1 Parent(s): ffb7693

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. .env +0 -1
  2. app.py +11 -10
  3. daily_usage.json +1 -1
.env CHANGED
@@ -1 +0,0 @@
1
- DEEPSEEK_API_KEY=sk-4e8ed6219f2a4a46a0af24eac64d1d90
 
 
app.py CHANGED
@@ -27,12 +27,12 @@ def save_usage(total_cost):
27
  load_dotenv(override=True)
28
 
29
 
30
- # client = OpenAI()
31
 
32
- client = OpenAI(
33
- api_key=os.getenv('DEEPSEEK_API_KEY'),
34
- base_url="https://api.deepseek.com/v1" # Example endpoint; replace with the actual DeepSeek endpoint
35
- )
36
  # === CONFIGURABLE BUDGET LIMIT (USD) ===
37
  USAGE_LIMIT_PER_DAY = 0.1 # USD
38
  USAGE_FILE = Path("daily_usage.json")
@@ -42,8 +42,8 @@ total_cost = load_usage()
42
 
43
  # Pricing reference (as of 2024-06): adjust if needed
44
  PRICES = {
45
- "gpt-4o-mini": {"input": 0.00025 / 1000, "output": 0.00025 / 1000},
46
- "deepseek-chat": {"input": 0.00027 / 1000, "output": 0.00007 / 1000}
47
  }
48
 
49
 
@@ -74,12 +74,13 @@ def chat(message, history):
74
  return "Daily usage limit reached. Please try again tomorrow."
75
 
76
  messages = [{"role": "system", "content": system_prompt}] + history + [{"role": "user", "content": message}]
77
- response = client.chat.completions.create(model="deepseek-chat", messages=messages)
78
  usage = response.usage
79
  input_tokens = usage.prompt_tokens
80
  output_tokens = usage.completion_tokens
81
- cost = (input_tokens * PRICES["deepseek-chat"]["input"] +
82
- output_tokens * PRICES["deepseek-chat"]["output"])
 
83
  total_cost += cost
84
  save_usage(total_cost)
85
  return response.choices[0].message.content
 
27
  load_dotenv(override=True)
28
 
29
 
30
+ client = OpenAI()
31
 
32
+ # client = OpenAI(
33
+ # api_key=os.getenv('DEEPSEEK_API_KEY'),
34
+ # base_url="https://api.deepseek.com/v1" # Example endpoint; replace with the actual DeepSeek endpoint
35
+ # )
36
  # === CONFIGURABLE BUDGET LIMIT (USD) ===
37
  USAGE_LIMIT_PER_DAY = 0.1 # USD
38
  USAGE_FILE = Path("daily_usage.json")
 
42
 
43
  # Pricing reference (as of 2024-06): adjust if needed
44
  PRICES = {
45
+ "gpt-4o-mini": {"input": 0.00015 / 1000, "output": 0.0006 / 1000},
46
+ "deepseek-chat": {"input": 0.00027 / 1000, "output": 0.0011 / 1000}
47
  }
48
 
49
 
 
74
  return "Daily usage limit reached. Please try again tomorrow."
75
 
76
  messages = [{"role": "system", "content": system_prompt}] + history + [{"role": "user", "content": message}]
77
+ response = client.chat.completions.create(model="gpt-4o-mini", messages=messages)
78
  usage = response.usage
79
  input_tokens = usage.prompt_tokens
80
  output_tokens = usage.completion_tokens
81
+ print(input_tokens, output_tokens)
82
+ cost = (input_tokens * PRICES["gpt-4o-mini"]["input"] +
83
+ output_tokens * PRICES["gpt-4o-mini"]["output"])
84
  total_cost += cost
85
  save_usage(total_cost)
86
  return response.choices[0].message.content
daily_usage.json CHANGED
@@ -1 +1 @@
1
- {"date": "2025-07-09", "total_cost": 0.012827749999999999}
 
1
+ {"date": "2025-07-09", "total_cost": 0.01973757}