基类:EventCustomLLM
围绕 You.com 的对话式智能与研究 API 的封装器。
每个API端点旨在生成对各种查询类型的对话式响应,包括相关时的内联引用和网络结果。
智能模式:
- 为各类问题提供快速可靠的解答
- 引用整个网页的URL
研究模式:
- 针对各类问题的深度解答,附带大量引用来源
- 引用与论断相关的具体网页片段
连接到 You.com API 需要一个 API 密钥,您可以在 https://api.you.com 获取。
如需更多信息,请查阅文档:
https://documentation.you.com/api-reference/。
参数:
| 名称 |
类型 |
描述 |
默认 |
mode
|
|
You.com 对话端点。可选择 "智能" 或 "研究" 模式
|
required
|
ydc_api_key
|
|
You.com API密钥,如果环境变量中未设置 YDC_API_KEY
|
required
|
workflows/handler.py 中的源代码llama_index/llms/you/base.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125 | class You(CustomLLM):
"""
Wrapper around You.com's conversational Smart and Research APIs.
Each API endpoint is designed to generate conversational
responses to a variety of query types, including inline citations
and web results when relevant.
Smart Mode:
- Quick, reliable answers for a variety of questions
- Cites the entire web page URL
Research Mode:
- In-depth answers with extensive citations for a variety of questions
- Cites the specific web page snippet relevant to the claim
To connect to the You.com api requires an API key which
you can get at https://api.you.com.
For more information, check out the documentations at
https://documentation.you.com/api-reference/.
Args:
mode: You.com conversational endpoints. Choose from "smart" or "research"
ydc_api_key: You.com API key, if `YDC_API_KEY` is not set in the environment
"""
mode: Literal["smart", "research"] = Field(
"smart",
description='You.com conversational endpoints. Choose from "smart" or "research"',
)
ydc_api_key: Optional[str] = Field(
None,
description="You.com API key, if `YDC_API_KEY` is not set in the envrioment",
)
@property
def metadata(self) -> LLMMetadata:
return LLMMetadata(
model_name=f"you.com-{self.mode}",
is_chat_model=True,
is_function_calling_model=False,
)
@llm_completion_callback()
def complete(self, prompt: str, **kwargs: Any) -> CompletionResponse:
response = _request(
self.endpoint,
api_key=self._api_key,
query=prompt,
)
return CompletionResponse(text=response["answer"], raw=response)
@llm_completion_callback()
def stream_complete(self, prompt: str, **kwargs: Any) -> CompletionResponseGen:
response = _request_stream(
self.endpoint,
api_key=self._api_key,
query=prompt,
)
completion = ""
for token in response:
completion += token
yield CompletionResponse(text=completion, delta=token)
@property
def endpoint(self) -> str:
if self.mode == "smart":
return SMART_ENDPOINT
return RESEARCH_ENDPOINT
@property
def _api_key(self) -> str:
return self.ydc_api_key or os.environ["YDC_API_KEY"]
|