chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
from open_chatcaht.chatchat_api import ChatChat
|
||||
|
||||
# todo 之后改为标准测试
|
||||
# chatchat = ChatChat()
|
||||
# for data in chatchat.chat.kb_chat(query='你好', kb_name="example_kb", model='glm-4'):
|
||||
# print(data)
|
||||
# for data in chatchat.chat.kb_chat(query='你好', kb_name="example_kb", model='glm-4'):
|
||||
# print(data)
|
||||
#
|
||||
# for data in chatchat.chat.file_chat(query='你好', knowledge_id="16d57480d9654104b405648f54d2485e", model_name='glm-4'):
|
||||
# print(data)
|
||||
# print(chatchat.chat.chat_feedback(message_id='a9bb673176cd4e34a827c63fd72945f2'))
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,53 @@
|
||||
import logging
|
||||
|
||||
from open_chatcaht.chatchat_api import ChatChat
|
||||
from open_chatcaht.types.knowledge_base.doc.upload_temp_docs_param import UploadTempDocsParam
|
||||
|
||||
# chatchat = ChatChat()
|
||||
# print('create_kb', chatchat.knowledge.create_kb(knowledge_base_name="example_kb"))
|
||||
# print('update_kb_info', chatchat.knowledge.update_kb_info(knowledge_base_name="example_kb", kb_info='aaaaaaa'))
|
||||
# print('list_kb', chatchat.knowledge.list_kb())
|
||||
# print('list_kb_docs_file', chatchat.knowledge.list_kb_docs_file(knowledge_base_name="samples"))
|
||||
# print('delete_kb', chatchat.knowledge.delete_kb(knowledge_base_name="example_kb"))
|
||||
# print('search_kb_docs', chatchat.knowledge.search_kb_docs(knowledge_base_name="example_kb", query="hello"))
|
||||
# print('upload_kb_docs', chatchat.knowledge.upload_kb_docs(
|
||||
# files=["data/upload_file1.txt", "data/upload_file2.txt"],
|
||||
# knowledge_base_name="example_kb",
|
||||
# ))
|
||||
# print('search_kb_docs', chatchat.knowledge.search_kb_docs(knowledge_base_name="example_kb", query="hello"))
|
||||
# print('recreate_vector_store', chatchat.knowledge.recreate_vector_store(
|
||||
# knowledge_base_name="samples",
|
||||
# ))
|
||||
# print('recreate_summary_vector_store', chatchat.knowledge.recreate_summary_vector_store(
|
||||
# knowledge_base_name="example_kb",
|
||||
# embed_model="embedding-2",
|
||||
# model_name="glm-4",
|
||||
# ))
|
||||
# for data in chatchat.knowledge.summary_file_to_vector_store(
|
||||
# knowledge_base_name="samples",
|
||||
# file_name="data/upload_file1.txt",
|
||||
# embed_model="embedding-2",
|
||||
# max_tokens=10000):
|
||||
# print(data)
|
||||
# print('summary_file_to_vector_store', chatchat.knowledge.summary_doc_ids_to_vector_store(
|
||||
# knowledge_base_name="samples",
|
||||
# file_name="data/upload_file1.txt",
|
||||
# ))
|
||||
# print('delete_kb_docs', chatchat.knowledge.delete_kb_docs(
|
||||
# knowledge_base_name="samples",
|
||||
# file_names=["upload_file1.txt"],
|
||||
# ))
|
||||
|
||||
# print(chatchat.knowledge.download_kb_doc_file(
|
||||
# knowledge_base_name='example_kb',
|
||||
# file_name='README.md'
|
||||
# ))
|
||||
# print(chatchat.knowledge.kb_doc_file_content(
|
||||
# knowledge_base_name='example_kb',
|
||||
# file_name='README.md'
|
||||
# ))
|
||||
# print(chatchat.knowledge.upload_temp_docs(
|
||||
# files=["README.md", ],
|
||||
# knowledge_id="4",
|
||||
# ))
|
||||
# print(chatchat.knowledge.search_temp_kb_docs(knowledge_id="cf414f74bca24fbdaece1ae8bb4d3970", query="hello"))
|
||||
@@ -0,0 +1,5 @@
|
||||
from open_chatcaht.chatchat_api import ChatChat
|
||||
|
||||
# chatchat = ChatChat()
|
||||
# print(chatchat.server.get_server_configs())
|
||||
# print(chatchat.server.get_prompt_template())
|
||||
@@ -0,0 +1,4 @@
|
||||
from open_chatcaht.chatchat_api import ChatChat
|
||||
from open_chatcaht.types.standard_openai.chat_input import OpenAIChatInput
|
||||
#
|
||||
# chatchat = ChatChat()
|
||||
@@ -0,0 +1,5 @@
|
||||
from open_chatcaht.chatchat_api import ChatChat
|
||||
|
||||
chatchat = ChatChat()
|
||||
print(chatchat.tool.list())
|
||||
print(chatchat.tool.call('calculate', {"text": "3+5/2"}))
|
||||
@@ -0,0 +1,86 @@
|
||||
from functools import wraps
|
||||
from typing import Type, get_type_hints
|
||||
|
||||
import httpx
|
||||
import requests
|
||||
from pydantic import BaseModel
|
||||
|
||||
from open_chatcaht.api_client import ApiClient
|
||||
from open_chatcaht.types.knowledge_base.delete_knowledge_base_param import DeleteKnowledgeBaseParam
|
||||
from open_chatcaht.types.response.base import ListResponse
|
||||
|
||||
base_url = "https://api.example.com"
|
||||
headers = {"Authorization": "Bearer token"}
|
||||
|
||||
|
||||
def http_request(method):
|
||||
def decorator(url, base_url='', headers=None, body_model: Type[BaseModel] = None, **options):
|
||||
headers = headers or {}
|
||||
|
||||
def wrapper(func):
|
||||
@wraps(func)
|
||||
def inner(*args, **kwargs):
|
||||
try:
|
||||
|
||||
print("args", args)
|
||||
print("kwargs", kwargs)
|
||||
# Prepare the request URL
|
||||
full_url = base_url + url
|
||||
|
||||
# Prepare the request data
|
||||
data = kwargs
|
||||
return_type = get_type_hints(func).get('return')
|
||||
print(f"Return type: {return_type}")
|
||||
print(body_model)
|
||||
print(f"body_model: {body_model}")
|
||||
# Send the HTTP request
|
||||
response = method(full_url, headers=headers, json=data)
|
||||
response.raise_for_status()
|
||||
|
||||
# Return the response JSON
|
||||
return response.json()
|
||||
except requests.exceptions.HTTPError as http_err:
|
||||
print(f"HTTP error occurred: {http_err}")
|
||||
except Exception as err:
|
||||
print(f"An error occurred: {err}")
|
||||
|
||||
return inner
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
# Usage example
|
||||
post = http_request(httpx.post)
|
||||
|
||||
|
||||
class MyAPIClient(ApiClient):
|
||||
|
||||
@post(url='/api/kb/recreate_summary_vector_store', base_url=base_url, headers=headers,
|
||||
body_model=DeleteKnowledgeBaseParam)
|
||||
def recreate_summary_vector_store(
|
||||
self,
|
||||
a: int,
|
||||
b: int
|
||||
) -> ListResponse:
|
||||
pass
|
||||
|
||||
|
||||
@post(url='/api/kb/recreate_summary_vector_store', base_url=base_url, headers=headers,
|
||||
body_model=DeleteKnowledgeBaseParam)
|
||||
def recreate_summary_vector_store(
|
||||
a: int,
|
||||
b: int
|
||||
) -> ListResponse:
|
||||
pass
|
||||
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
# Call the decorated function
|
||||
# response = recreate_summary_vector_store(a=1, b=1)
|
||||
# print(response)
|
||||
api_client = MyAPIClient()
|
||||
response = api_client.recreate_summary_vector_store(a=1, b=2)
|
||||
print("response", response)
|
||||
@@ -0,0 +1,70 @@
|
||||
import inspect
|
||||
from functools import wraps
|
||||
import requests
|
||||
|
||||
|
||||
class HTTPClient:
|
||||
def __init__(self, base_url='', headers=None):
|
||||
self.base_url = base_url
|
||||
self.headers = headers or {}
|
||||
|
||||
def http_request(self, method):
|
||||
def decorator(url, **options):
|
||||
headers = options.get('headers', self.headers)
|
||||
|
||||
def wrapper(func):
|
||||
@wraps(func)
|
||||
def inner(*args, **kwargs):
|
||||
try:
|
||||
# Prepare the request URL
|
||||
full_url = self.base_url + url
|
||||
instance = args[0] # Assuming func is a method of the class
|
||||
print(f"Instance: {instance}")
|
||||
# Prepare the request data from function arguments
|
||||
data = kwargs
|
||||
print(kwargs)
|
||||
# Send the HTTP request
|
||||
response = method(full_url, headers=headers, json=data)
|
||||
response.raise_for_status()
|
||||
|
||||
# Return the response JSON
|
||||
return response.json()
|
||||
except requests.exceptions.HTTPError as http_err:
|
||||
print(f"HTTP error occurred: {http_err}")
|
||||
except Exception as err:
|
||||
print(f"An error occurred: {err}")
|
||||
|
||||
return inner
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
def post(self, url, **options):
|
||||
print(self)
|
||||
|
||||
# Define a function that applies the decorator
|
||||
def decorator(func):
|
||||
return self.http_request(requests.post)(url, **options)(func)
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
app: HTTPClient = HTTPClient()
|
||||
|
||||
|
||||
# Example usage of the class and its decorators
|
||||
class MyAPIClient(HTTPClient):
|
||||
def __init__(self):
|
||||
super().__init__(base_url="https://api.example.com", headers={"Authorization": "Bearer token"})
|
||||
|
||||
@app.post(url='/api/kb/recreate_summary_vector_store')
|
||||
def recreate_summary_vector_store(self, a: int, b: int):
|
||||
...
|
||||
|
||||
|
||||
# Example call to the decorated method
|
||||
if __name__ == "__main__":
|
||||
client = MyAPIClient()
|
||||
response = client.recreate_summary_vector_store(a=1, b=1)
|
||||
print(response)
|
||||
Reference in New Issue
Block a user