ntnuhjchen commited on
Commit
a7a39a5
0 Parent(s):

initial commit

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +13 -0
  3. app.py +34 -0
  4. requirements.txt +0 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: New Space
3
+ emoji: 🐨
4
+ colorFrom: red
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 5.6.0
8
+ app_file: app.py
9
+ pinned: false
10
+ short_description: cool english
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Please update your assistant id and api key here:
2
+ API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJEVkNBU1NJIiwic3ViIjoiQlVJTFRJTkFETUlOIiwiYXVkIjpbIkRWQ0FTU0kiXSwiaWF0IjoxNzMxNDg3NTM1LCJqdGkiOiJjYzAwMWEwZS0yNWEwLTQzYmMtOGIxYi1mM2I4ZjJkNDQxY2IifQ.Ye45WBKwIS1PIHZ0dyEJ4AFtVL_1wIfPpfpi7vPuNOs"
3
+ ASSISTANT_ID = "asst_dvc_r1iHNC1t7pRZzlrT7G983GsW"
4
+ ASSISTANT_API = "https://prod.dvcbot.net/api/assts/v1"
5
+
6
+ import micropip; await micropip.install('openai==1.39.0'); from pyodide.http import pyfetch; import httpx; import gradio as gr
7
+ from openai import AsyncOpenAI
8
+ from datetime import datetime
9
+ import json
10
+
11
+ class Transport(httpx.AsyncBaseTransport):
12
+ async def handle_async_request(self, request: httpx.Request):
13
+ resp = await pyfetch(str(request.url), method=request.method, headers=dict(request.headers.items()), body=json.dumps(json.loads(request.content), ensure_ascii=False).encode() if request.method != 'GET' and request.method != 'DELETE' else None)
14
+ return httpx.Response(resp.status, headers=resp.headers, stream=httpx.ByteStream(await resp.bytes()))
15
+
16
+ client = AsyncOpenAI(base_url=ASSISTANT_API, api_key=API_KEY, http_client=httpx.AsyncClient(transport=Transport()))
17
+ if __name__ == "__main__":
18
+ async def send_message(message, history):
19
+ thread = await client.beta.threads.create(messages=[{"role": "user" if i == 0 else "assistant", "content": c} for p in history for i, c in enumerate(p)])
20
+ await client.beta.threads.messages.create(thread_id=thread.id, role='user', content=message)
21
+ run = await client.beta.threads.runs.create_and_poll(thread_id=thread.id, assistant_id=ASSISTANT_ID, additional_instructions=f"\nThe current time is: {datetime.now()}", timeout=2.0)
22
+ while run.status == 'requires_action' and run.required_action:
23
+ outputs = []
24
+ for call in run.required_action.submit_tool_outputs.tool_calls:
25
+ resp = await client._client.post(ASSISTANT_API+'/pluginapi', params={"tid": thread.id, "aid": ASSISTANT_ID, "pid": call.function.name}, headers={"Authorization": "Bearer " + API_KEY}, json=json.loads(call.function.arguments))
26
+ outputs.append({"tool_call_id": call.id, "output": resp.text[:8000]})
27
+ run = await client.beta.threads.runs.submit_tool_outputs_and_poll(run_id=run.id, thread_id=thread.id, tool_outputs=outputs, timeout=2.0)
28
+ if run.status == 'failed' and run.last_error:
29
+ return run.last_error.model_dump_json()
30
+ msgs = await client.beta.threads.messages.list(thread_id=thread.id, order='desc')
31
+ await client.beta.threads.delete(thread_id=thread.id)
32
+ return msgs.data[0].content[0].text.value
33
+ demo = gr.ChatInterface(send_message)
34
+ demo.launch()
requirements.txt ADDED
File without changes