Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

合并更改到主分支 #1

Open
wants to merge 88 commits into
base: fix-and-improve
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
56504b5
minor bug fix
tripathiarpan20 Aug 10, 2023
e8c5262
fixed typos in prompt
tripathiarpan20 Aug 10, 2023
8f9427e
Merge pull request #13 from tripathiarpan20/main
joonspk-research Aug 10, 2023
07dc393
Merge pull request #11 from mattkanwisher/main
joonspk-research Aug 10, 2023
6b68194
Merge pull request #10 from guili618/my_dev
joonspk-research Aug 10, 2023
f109996
Update README.md
eltociear Aug 10, 2023
b2a1d1d
Merge pull request #24 from eltociear/main-1
joonspk-research Aug 11, 2023
e5456f3
fix(backend): replace deprecated models.
drudilorenzo Apr 26, 2024
30b2275
feat: simplify execution w/ scripts.
drudilorenzo Apr 26, 2024
e1316cc
feat: add cost logging.
drudilorenzo Apr 27, 2024
80ce0ff
fix: fix scripts.
drudilorenzo May 3, 2024
c1e0da3
feat: cost logging improvement.
drudilorenzo May 3, 2024
4a0fdec
feat: add cost logger singleton.
drudilorenzo May 3, 2024
a88e628
feat: thread-safe singleton.
drudilorenzo May 3, 2024
b6978ef
fix: remove clustrmaps.
drudilorenzo May 6, 2024
3df2f87
fix: create movement directory.
drudilorenzo May 6, 2024
007dd28
feat: improve project config.
drudilorenzo May 7, 2024
3da6e31
tbd: add current bug.
drudilorenzo May 7, 2024
34ba541
feat: untrack temp file.
drudilorenzo May 7, 2024
bed92a6
Add readme.
drudilorenzo May 7, 2024
2fe77a1
Update README.md
drudilorenzo May 7, 2024
b31ef7a
Update README.md
drudilorenzo May 7, 2024
c38601f
Update README.md
drudilorenzo May 7, 2024
eecdf47
(docs): improve readme.
drudilorenzo May 13, 2024
56d6123
feat: log on file.
drudilorenzo May 14, 2024
431b647
feat: create directory.
drudilorenzo May 14, 2024
ededeab
(exec): add skip-morning simulation.
drudilorenzo May 15, 2024
f898a1b
(scripts): improve backend scripts.
drudilorenzo May 15, 2024
2b9f5d1
feat: restart execution in case of failure.
drudilorenzo May 15, 2024
abbb8a6
(docs): improve readme.
drudilorenzo May 15, 2024
3528724
Update README.md
drudilorenzo May 15, 2024
de55f22
Update README.md
drudilorenzo May 15, 2024
89fdbbc
add tracing func, add fake get for frontend refresh, add data files
Laz4rz May 16, 2024
abf3e24
add setup info
Laz4rz May 16, 2024
22b7500
feat: save checkpoints.
drudilorenzo May 17, 2024
3465f21
add test elections setup with 5 voters
Laz4rz May 18, 2024
70464fd
fix base files in .gitignore
Laz4rz May 18, 2024
95cc4a6
fix elections setup
Laz4rz May 18, 2024
5bf1be3
feat: execution w/o ui.
drudilorenzo May 22, 2024
d66f7f1
Update README.md
drudilorenzo May 22, 2024
f3989e4
feat: track utils file.
drudilorenzo May 22, 2024
074f96f
fix: fix requirements.
drudilorenzo May 22, 2024
909aff9
fix: fix logger version.
drudilorenzo May 22, 2024
c3a801c
add browser path support
Laz4rz May 22, 2024
661a326
add survey ipynb, add direct access to agent analysis
Laz4rz May 22, 2024
ce77101
add single and multisurveys, expand on direct interview access
Laz4rz May 22, 2024
0724391
update potential election setup problems
Laz4rz May 23, 2024
fcf8719
finish test 2 + 5 results
Laz4rz May 23, 2024
edf404b
fix steps diff count for filtered
Laz4rz May 23, 2024
96cc3dc
fix: update curr time.
drudilorenzo May 24, 2024
ee4cca6
feat: improve autorun script.
drudilorenzo May 24, 2024
73aba73
fix steps diff count for filtered
Laz4rz May 24, 2024
b29a732
fix test setup
Laz4rz May 24, 2024
cb164b9
add ideas and todo
Laz4rz May 24, 2024
4fefeb5
add reversed setup
Laz4rz May 24, 2024
3d9d81f
feat: Add port config.
drudilorenzo May 25, 2024
3fd8e76
fix: issue 111.
drudilorenzo May 25, 2024
b35c24a
fix: fix log file name.
drudilorenzo May 25, 2024
712d1c6
add zoom on Z and X
ketsapiwiq May 20, 2024
06f5a1e
fix: close thread.
drudilorenzo May 25, 2024
8009fa2
feat: limit cpu usage.
drudilorenzo May 25, 2024
d282c48
Merge pull request #3 from ketsapiwiq/zoom
drudilorenzo May 27, 2024
f6312ca
fix(ui): lower zoom speed.
drudilorenzo May 27, 2024
4fcbc2d
Update README.md
drudilorenzo May 27, 2024
73c9514
fix: no ui run.
drudilorenzo May 27, 2024
7c40c31
Refactor.
drudilorenzo May 28, 2024
6f1189e
Update README.md
drudilorenzo May 28, 2024
cde122a
Update README.md
drudilorenzo May 28, 2024
1732985
fix output parsing
drudilorenzo Jun 3, 2024
6938737
完成科大讯飞星火认知大模型的接入(尚存在embedding失败导致的错误)
fengye7 Jan 8, 2025
d88bf42
Update .gitignore
fengye7 Jan 8, 2025
9e7d3ad
Merge branch 'fix-and-improve' of github.com:edsml-sm2323/generative_…
fengye7 Jan 8, 2025
8658c72
完成科大讯飞星火认知大模型的接入(尚存在embedding失败导致的错误)
fengye7 Jan 8, 2025
d225cc4
接入星火大模型;1未定位bug待解决,见文档
fengye7 Jan 9, 2025
42f1d8e
接入星火大模型;1未定位bug待解决,见文档
fengye7 Jan 9, 2025
e2448f8
完成星火大模型的接入工作:run 1测试完毕
fengye7 Jan 10, 2025
9751746
测试中转链接的可用性
fengye7 Jan 14, 2025
baea681
测试中转链接的可用性
fengye7 Jan 14, 2025
2447e1a
开发前后端:搭建环境
fengye7 Feb 13, 2025
acdef5e
前端页面原型初步完成
fengye7 Feb 13, 2025
10dd866
前端页面原型-首页修改
fengye7 Feb 13, 2025
2e07fd8
empitome平台集成django应用框架建立
fengye7 Feb 14, 2025
f15ae41
empitome平台集成django应用框架建立
fengye7 Feb 14, 2025
e61c9c7
django接口测试
fengye7 Feb 14, 2025
c4a52b3
添加视频播放接口
fengye7 Feb 17, 2025
7fb3d91
暂存代码
fengye7 Feb 18, 2025
152dc23
接口初步和docker部署
fengye7 Feb 18, 2025
f862032
开发empitome平台接口-过程commit1
fengye7 Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add cost logging.
  • Loading branch information
drudilorenzo committed Apr 27, 2024
commit e1316cc30b75c8cd58a7ac318188f55923db7f7c
117 changes: 117 additions & 0 deletions cost_viz.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: openai-cost-logger==0.3.0 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (0.3.0)\n",
"Requirement already satisfied: openai in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from openai-cost-logger==0.3.0) (1.13.3)\n",
"Requirement already satisfied: pandas in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from openai-cost-logger==0.3.0) (2.0.3)\n",
"Requirement already satisfied: matplotlib in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from openai-cost-logger==0.3.0) (3.6.3)\n",
"Requirement already satisfied: contourpy>=1.0.1 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from matplotlib->openai-cost-logger==0.3.0) (1.2.1)\n",
"Requirement already satisfied: cycler>=0.10 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from matplotlib->openai-cost-logger==0.3.0) (0.11.0)\n",
"Requirement already satisfied: fonttools>=4.22.0 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from matplotlib->openai-cost-logger==0.3.0) (4.51.0)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from matplotlib->openai-cost-logger==0.3.0) (1.4.4)\n",
"Requirement already satisfied: numpy>=1.19 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from matplotlib->openai-cost-logger==0.3.0) (1.25.2)\n",
"Requirement already satisfied: packaging>=20.0 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from matplotlib->openai-cost-logger==0.3.0) (23.0)\n",
"Requirement already satisfied: pillow>=6.2.0 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from matplotlib->openai-cost-logger==0.3.0) (8.4.0)\n",
"Requirement already satisfied: pyparsing>=2.2.1 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from matplotlib->openai-cost-logger==0.3.0) (3.0.6)\n",
"Requirement already satisfied: python-dateutil>=2.7 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from matplotlib->openai-cost-logger==0.3.0) (2.8.2)\n",
"Requirement already satisfied: anyio<5,>=3.5.0 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from openai->openai-cost-logger==0.3.0) (4.3.0)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from openai->openai-cost-logger==0.3.0) (1.9.0)\n",
"Requirement already satisfied: httpx<1,>=0.23.0 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from openai->openai-cost-logger==0.3.0) (0.27.0)\n",
"Requirement already satisfied: pydantic<3,>=1.9.0 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from openai->openai-cost-logger==0.3.0) (2.7.1)\n",
"Requirement already satisfied: sniffio in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from openai->openai-cost-logger==0.3.0) (1.3.0)\n",
"Requirement already satisfied: tqdm>4 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from openai->openai-cost-logger==0.3.0) (4.62.3)\n",
"Requirement already satisfied: typing-extensions<5,>=4.7 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from openai->openai-cost-logger==0.3.0) (4.11.0)\n",
"Requirement already satisfied: pytz>=2020.1 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from pandas->openai-cost-logger==0.3.0) (2021.3)\n",
"Requirement already satisfied: tzdata>=2022.1 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from pandas->openai-cost-logger==0.3.0) (2024.1)\n",
"Requirement already satisfied: idna>=2.8 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from anyio<5,>=3.5.0->openai->openai-cost-logger==0.3.0) (3.3)\n",
"Requirement already satisfied: exceptiongroup>=1.0.2 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from anyio<5,>=3.5.0->openai->openai-cost-logger==0.3.0) (1.1.0)\n",
"Requirement already satisfied: certifi in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from httpx<1,>=0.23.0->openai->openai-cost-logger==0.3.0) (2021.10.8)\n",
"Requirement already satisfied: httpcore==1.* in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from httpx<1,>=0.23.0->openai->openai-cost-logger==0.3.0) (1.0.5)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai->openai-cost-logger==0.3.0) (0.14.0)\n",
"Requirement already satisfied: annotated-types>=0.4.0 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from pydantic<3,>=1.9.0->openai->openai-cost-logger==0.3.0) (0.6.0)\n",
"Requirement already satisfied: pydantic-core==2.18.2 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from pydantic<3,>=1.9.0->openai->openai-cost-logger==0.3.0) (2.18.2)\n",
"Requirement already satisfied: six>=1.5 in /home/drudao/anaconda3/envs/simulacra/lib/python3.9/site-packages (from python-dateutil>=2.7->matplotlib->openai-cost-logger==0.3.0) (1.16.0)\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install openai-cost-logger==0.3.0"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from openai_cost_logger import DEFAULT_LOG_PATH\n",
"from openai_cost_logger import OpenAICostLoggerViz"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"LOG_PATH = DEFAULT_LOG_PATH"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"OpenAICostLoggerViz.print_total_cost(path=LOG_PATH)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "simulacra",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
43 changes: 33 additions & 10 deletions reverie/backend_server/persona/prompt_template/gpt_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,38 @@
Description: Wrapper functions for calling OpenAI APIs.
"""
import json
import random
import openai
import time

from utils import *

from openai_cost_logger import OpenAICostLogger
from openai_cost_logger import DEFAULT_LOG_PATH
import threading

openai.api_key = openai_api_key
exp_name = "simulacra-test-1"
cost_upperbound = 10

cost_logger = OpenAICostLogger(
experiment_name = exp_name,
log_folder = DEFAULT_LOG_PATH,
cost_upperbound = cost_upperbound
)
lock = threading.Lock() # Lock to ensure thread safety when updating the cost logger.

def update_cost_logger(response: dict, input_cost: float, output_cost: float = 0) -> None:
"""
Update the cost logger with the cost of the response.

Args:
response (dict): The response from the OpenAI API.
input_cost (float): The cost of the input to the API.
output_cost (float. Optional): The cost of the output from the API. Defaults to 0.
"""
# Need to acquire the lock since the cost_logger is shared among threads.
with lock:
cost_logger.update_cost(response=response, input_cost=input_cost, output_cost=output_cost)

def temp_sleep(seconds=0.1):
time.sleep(seconds)
Expand All @@ -23,9 +48,9 @@ def ChatGPT_single_request(prompt):
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}]
)
update_cost_logger(completion, input_cost=0.5, output_cost=1.5)
return completion["choices"][0]["message"]["content"]


# ============================================================================
# #####################[SECTION 1: CHATGPT-3 STRUCTURE] ######################
# ============================================================================
Expand All @@ -49,6 +74,7 @@ def GPT4_request(prompt):
model="gpt-4",
messages=[{"role": "user", "content": prompt}]
)
update_cost_logger(completion, input_cost=30.0, output_cost=60.0)
return completion["choices"][0]["message"]["content"]

except:
Expand All @@ -74,6 +100,7 @@ def ChatGPT_request(prompt):
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}]
)
update_cost_logger(completion, input_cost=0.5, output_cost=1.5)
return completion["choices"][0]["message"]["content"]

except:
Expand Down Expand Up @@ -145,10 +172,6 @@ def ChatGPT_safe_generate_response(prompt,
end_index = curr_gpt_response.rfind('}') + 1
curr_gpt_response = curr_gpt_response[:end_index]
curr_gpt_response = json.loads(curr_gpt_response)["output"]

# print ("---ashdfaf")
# print (curr_gpt_response)
# print ("000asdfhia")

if func_validate(curr_gpt_response, prompt=prompt):
return func_clean_up(curr_gpt_response, prompt=prompt)
Expand Down Expand Up @@ -218,6 +241,7 @@ def GPT_request(prompt, gpt_parameter):
presence_penalty=gpt_parameter["presence_penalty"],
stream=gpt_parameter["stream"],
stop=gpt_parameter["stop"],)
update_cost_logger(response=response, input_cost=0.5, output_cost=1.5)
return response.choices[0].text
except:
print ("TOKEN LIMIT EXCEEDED")
Expand Down Expand Up @@ -277,8 +301,9 @@ def get_embedding(text, model="text-embedding-ada-002"):
text = text.replace("\n", " ")
if not text:
text = "this is blank"
return openai.Embedding.create(
input=[text], model=model)['data'][0]['embedding']
response = openai.Embedding.create(input=[text], model=model)
update_cost_logger(response=response, input_cost=0.1, output_cost=0.0)
return response['data'][0]['embedding']


if __name__ == '__main__':
Expand Down Expand Up @@ -327,5 +352,3 @@ def __func_clean_up(gpt_response):