Files
heyong.fu a17c65c4bc feat: rag
2026-05-06 11:35:10 +08:00

118 lines
2.7 KiB
Python

# for i in range(2, 10):
# print(i)
# DEFAULT_COLLECTION_NAME = "rag"
# def abc(collection_name=DEFAULT_COLLECTION_NAME):
# print(collection_name)
# abc()
# aaa = " "
# print(not aaa.strip())
# o = {"a": 1, "b": 2}
# for value in o.values():
# # print("k", key)
# print("value", value)
# from typing import Optional, Iterator
# class ChatCompletions:
# def __init__(self, client):
# self._client = client
# def create(self, model):
# print(f"{model}")
# class ChatResource:
# def __init__(self, client):
# self._client = client
# @property
# def completions(self) -> ChatCompletions:
# return ChatCompletions(self._client)
# class OpenAI:
# def __init__(
# self,
# api_key: Optional[str] = None,
# base_url: str = "https://api.openai.com/v1",
# timeout: float = 60.0,
# ):
# self.api_key = "111"
# if not self.api_key:
# raise ValueError(
# f"API密钥未设置,请设置api_key参数或者环境变量OPENAI_API_KEY"
# )
# self.base_url = base_url.rstrip("/")
# self.timeout = timeout
# @property
# def chat(self) -> ChatResource:
# return ChatResource(self)
# client = OpenAI()
# client.chat.completions.create(model="openai")
# class Obj:
# def __init__(self, data):
# self.o = data.get("o")
# class Message:
# def __init__(self, data):
# self.obj = Obj(data)
# msg = Message({"o": "112"})
# print(msg.obj.o)
class Choice:
def __init__(self, data):
self.index = data.get("index")
self.message = data.get("message")
self.finish_reason = data.get("finish_reason")
class Completion:
def __init__(self, data):
self.id = data.get("id")
self.object = data.get("object")
self.created = data.get("created")
self.model = data.get("model")
self.choices = [Choice(choice) for choice in data.get("choices", [])]
completion = Completion({"id": "123", "object": "completion", "created": 1718000000, "model": "gpt-3.5-turbo",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Hello, how can I help you today?"}, "finish_reason": "stop"
}
]
})
class Student:
def __init__(self, name, age, score):
self.name = name # 实例属性
self.age = age
self.score = score
def introduce(self):
print(f"我是{self.name},今年{self.age}岁,分数{self.score}")
def is_pass(self):
return self.score >= 60
# 创建一个学生对象
stu1 = Student("Alice", 20, 85)
print(stu1.name)