FAST API

FAST API

akasha 提供get_response, ask_self, ask_whole_file, get_summary的api server

啟動

1
2
akasha api (–port {port} –host {host} –workers {num_of_workers})

Example

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import requests
import os

HOST = os.getenv("API_HOST", "http://127.0.0.1")
PORT = os.getenv("API_PORT", "8000")
urls = {
"summary": f"{HOST}:{PORT}/get_summary",
"qa": f"{HOST}:{PORT}/get_response",
"self": f"{HOST}:{PORT}/ask_self",
"file": f"{HOST}:{PORT}/ask_whole_file",
}

openai_config = {
"azure_key": {your api key},
"azure_base": {your api base},
}

self_data = {
"prompt": "太陽電池技術?",
"info": "太陽能電池技術5塊錢",
"model": "openai:gpt-3.5-turbo",
"system_prompt": "",
"max_input_tokens": 3000,
"temperature": 0.0,
"openai_config": openai_config
}

file_data = {
"doc_path": "docs/mic/20230317_5軸工具機因應市場訴求改變的發展態勢.pdf",
"prompt": "五軸是什麼?",
"chunk_size": 1000,
"model": "openai:gpt-3.5-turbo",
"embedding_model": "openai:text-embedding-ada-002",
"system_prompt": "",
"max_input_tokens": 3000,
"temperature": 0.0,
"openai_config": openai_config
}

chat_data = {
"doc_path": "docs/pns/",
"prompt": "太陽電池技術?",
"chunk_size": 1000,
"model": "openai:gpt-3.5-turbo",
"embedding_model": "openai:text-embedding-ada-002",
"search_type": 'auto',
"system_prompt": "",
"max_input_tokens": 3000,
"temperature": 0.0,
"openai_config": openai_config
}
summary_data = {
"file_path": "docs/pns/2484.txt",
"model": "openai:gpt-3.5-turbo",
"summary_type": "reduce_map",
"summary_len": 500,
"system_prompt": "",
"openai_config": openai_config
}

# chat_response = requests.post(urls["qa"], json=chat_data).json()
# print(chat_response)

# sum_response = requests.post(
# urls["summary"],
# json=summary_data,
# ).json()

# print(sum_response)

self_response = requests.post(urls["self"], json=self_data).json()
print(self_response)
file_response = requests.post(urls["file"], json=file_data).json()
print(file_response)