mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-04 12:18:24 +00:00
patch: remove usage of llm, chat model __call__ (#20788)
- `llm(prompt)` -> `llm.invoke(prompt)` - `llm(prompt=prompt` -> `llm.invoke(prompt)` (same with `messages=`) - `llm(prompt, callbacks=callbacks)` -> `llm.invoke(prompt, config={"callbacks": callbacks})` - `llm(prompt, **kwargs)` -> `llm.invoke(prompt, **kwargs)`
This commit is contained in:
parent
9b7fb381a4
commit
481d3855dc
@ -256,7 +256,7 @@
|
|||||||
" \"\"\"Make image summary\"\"\"\n",
|
" \"\"\"Make image summary\"\"\"\n",
|
||||||
" model = ChatVertexAI(model_name=\"gemini-pro-vision\", max_output_tokens=1024)\n",
|
" model = ChatVertexAI(model_name=\"gemini-pro-vision\", max_output_tokens=1024)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" msg = model(\n",
|
" msg = model.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" HumanMessage(\n",
|
" HumanMessage(\n",
|
||||||
" content=[\n",
|
" content=[\n",
|
||||||
|
@ -90,7 +90,7 @@
|
|||||||
" ) -> AIMessage:\n",
|
" ) -> AIMessage:\n",
|
||||||
" messages = self.update_messages(input_message)\n",
|
" messages = self.update_messages(input_message)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" output_message = self.model(messages)\n",
|
" output_message = self.model.invoke(messages)\n",
|
||||||
" self.update_messages(output_message)\n",
|
" self.update_messages(output_message)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" return output_message"
|
" return output_message"
|
||||||
|
@ -362,7 +362,7 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"llm = OpenAI()\n",
|
"llm = OpenAI()\n",
|
||||||
"llm(query)"
|
"llm.invoke(query)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -108,7 +108,7 @@
|
|||||||
" return obs_message\n",
|
" return obs_message\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def _act(self):\n",
|
" def _act(self):\n",
|
||||||
" act_message = self.model(self.message_history)\n",
|
" act_message = self.model.invoke(self.message_history)\n",
|
||||||
" self.message_history.append(act_message)\n",
|
" self.message_history.append(act_message)\n",
|
||||||
" action = int(self.action_parser.parse(act_message.content)[\"action\"])\n",
|
" action = int(self.action_parser.parse(act_message.content)[\"action\"])\n",
|
||||||
" return action\n",
|
" return action\n",
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
" Applies the chatmodel to the message history\n",
|
" Applies the chatmodel to the message history\n",
|
||||||
" and returns the message string\n",
|
" and returns the message string\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" message = self.model(\n",
|
" message = self.model.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" self.system_message,\n",
|
" self.system_message,\n",
|
||||||
" HumanMessage(content=\"\\n\".join(self.message_history + [self.prefix])),\n",
|
" HumanMessage(content=\"\\n\".join(self.message_history + [self.prefix])),\n",
|
||||||
|
@ -79,7 +79,7 @@
|
|||||||
" Applies the chatmodel to the message history\n",
|
" Applies the chatmodel to the message history\n",
|
||||||
" and returns the message string\n",
|
" and returns the message string\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" message = self.model(\n",
|
" message = self.model.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" self.system_message,\n",
|
" self.system_message,\n",
|
||||||
" HumanMessage(content=\"\\n\".join(self.message_history + [self.prefix])),\n",
|
" HumanMessage(content=\"\\n\".join(self.message_history + [self.prefix])),\n",
|
||||||
@ -234,7 +234,7 @@
|
|||||||
" termination_clause=self.termination_clause if self.stop else \"\",\n",
|
" termination_clause=self.termination_clause if self.stop else \"\",\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
"\n",
|
"\n",
|
||||||
" self.response = self.model(\n",
|
" self.response = self.model.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" self.system_message,\n",
|
" self.system_message,\n",
|
||||||
" HumanMessage(content=response_prompt),\n",
|
" HumanMessage(content=response_prompt),\n",
|
||||||
@ -263,7 +263,7 @@
|
|||||||
" speaker_names=speaker_names,\n",
|
" speaker_names=speaker_names,\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
"\n",
|
"\n",
|
||||||
" choice_string = self.model(\n",
|
" choice_string = self.model.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" self.system_message,\n",
|
" self.system_message,\n",
|
||||||
" HumanMessage(content=choice_prompt),\n",
|
" HumanMessage(content=choice_prompt),\n",
|
||||||
@ -299,7 +299,7 @@
|
|||||||
" ),\n",
|
" ),\n",
|
||||||
" next_speaker=self.next_speaker,\n",
|
" next_speaker=self.next_speaker,\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
" message = self.model(\n",
|
" message = self.model.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" self.system_message,\n",
|
" self.system_message,\n",
|
||||||
" HumanMessage(content=next_prompt),\n",
|
" HumanMessage(content=next_prompt),\n",
|
||||||
|
@ -71,7 +71,7 @@
|
|||||||
" Applies the chatmodel to the message history\n",
|
" Applies the chatmodel to the message history\n",
|
||||||
" and returns the message string\n",
|
" and returns the message string\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" message = self.model(\n",
|
" message = self.model.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" self.system_message,\n",
|
" self.system_message,\n",
|
||||||
" HumanMessage(content=\"\\n\".join(self.message_history + [self.prefix])),\n",
|
" HumanMessage(content=\"\\n\".join(self.message_history + [self.prefix])),\n",
|
||||||
@ -164,7 +164,7 @@
|
|||||||
" message_history=\"\\n\".join(self.message_history),\n",
|
" message_history=\"\\n\".join(self.message_history),\n",
|
||||||
" recent_message=self.message_history[-1],\n",
|
" recent_message=self.message_history[-1],\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
" bid_string = self.model([SystemMessage(content=prompt)]).content\n",
|
" bid_string = self.model.invoke([SystemMessage(content=prompt)]).content\n",
|
||||||
" return bid_string"
|
" return bid_string"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -129,7 +129,7 @@
|
|||||||
" return obs_message\n",
|
" return obs_message\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def _act(self):\n",
|
" def _act(self):\n",
|
||||||
" act_message = self.model(self.message_history)\n",
|
" act_message = self.model.invoke(self.message_history)\n",
|
||||||
" self.message_history.append(act_message)\n",
|
" self.message_history.append(act_message)\n",
|
||||||
" action = int(self.action_parser.parse(act_message.content)[\"action\"])\n",
|
" action = int(self.action_parser.parse(act_message.content)[\"action\"])\n",
|
||||||
" return action\n",
|
" return action\n",
|
||||||
|
@ -84,7 +84,7 @@
|
|||||||
" Applies the chatmodel to the message history\n",
|
" Applies the chatmodel to the message history\n",
|
||||||
" and returns the message string\n",
|
" and returns the message string\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" message = self.model(\n",
|
" message = self.model.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" self.system_message,\n",
|
" self.system_message,\n",
|
||||||
" HumanMessage(content=\"\\n\".join(self.message_history + [self.prefix])),\n",
|
" HumanMessage(content=\"\\n\".join(self.message_history + [self.prefix])),\n",
|
||||||
|
@ -70,7 +70,7 @@
|
|||||||
" Applies the chatmodel to the message history\n",
|
" Applies the chatmodel to the message history\n",
|
||||||
" and returns the message string\n",
|
" and returns the message string\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" message = self.model(\n",
|
" message = self.model.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" self.system_message,\n",
|
" self.system_message,\n",
|
||||||
" HumanMessage(content=\"\\n\".join(self.message_history + [self.prefix])),\n",
|
" HumanMessage(content=\"\\n\".join(self.message_history + [self.prefix])),\n",
|
||||||
|
@ -194,7 +194,7 @@
|
|||||||
"llm = OpenAI(\n",
|
"llm = OpenAI(\n",
|
||||||
" temperature=0, callbacks=[LabelStudioCallbackHandler(project_name=\"My Project\")]\n",
|
" temperature=0, callbacks=[LabelStudioCallbackHandler(project_name=\"My Project\")]\n",
|
||||||
")\n",
|
")\n",
|
||||||
"print(llm(\"Tell me a joke\"))"
|
"print(llm.invoke(\"Tell me a joke\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -270,7 +270,7 @@
|
|||||||
" )\n",
|
" )\n",
|
||||||
" ]\n",
|
" ]\n",
|
||||||
")\n",
|
")\n",
|
||||||
"llm_results = chat_llm(\n",
|
"llm_results = chat_llm.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" SystemMessage(content=\"Always use a lot of emojis\"),\n",
|
" SystemMessage(content=\"Always use a lot of emojis\"),\n",
|
||||||
" HumanMessage(content=\"Tell me a joke\"),\n",
|
" HumanMessage(content=\"Tell me a joke\"),\n",
|
||||||
|
@ -107,7 +107,7 @@ User tracking allows you to identify your users, track their cost, conversations
|
|||||||
from langchain_community.callbacks.llmonitor_callback import LLMonitorCallbackHandler, identify
|
from langchain_community.callbacks.llmonitor_callback import LLMonitorCallbackHandler, identify
|
||||||
|
|
||||||
with identify("user-123"):
|
with identify("user-123"):
|
||||||
llm("Tell me a joke")
|
llm.invoke("Tell me a joke")
|
||||||
|
|
||||||
with identify("user-456", user_props={"email": "user456@test.com"}):
|
with identify("user-456", user_props={"email": "user456@test.com"}):
|
||||||
agen.run("Who is Leo DiCaprio's girlfriend?")
|
agen.run("Who is Leo DiCaprio's girlfriend?")
|
||||||
|
@ -103,7 +103,7 @@
|
|||||||
" temperature=0,\n",
|
" temperature=0,\n",
|
||||||
" callbacks=[PromptLayerCallbackHandler(pl_tags=[\"chatopenai\"])],\n",
|
" callbacks=[PromptLayerCallbackHandler(pl_tags=[\"chatopenai\"])],\n",
|
||||||
")\n",
|
")\n",
|
||||||
"llm_results = chat_llm(\n",
|
"llm_results = chat_llm.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" HumanMessage(content=\"What comes after 1,2,3 ?\"),\n",
|
" HumanMessage(content=\"What comes after 1,2,3 ?\"),\n",
|
||||||
" HumanMessage(content=\"Tell me another joke?\"),\n",
|
" HumanMessage(content=\"Tell me another joke?\"),\n",
|
||||||
@ -129,10 +129,11 @@
|
|||||||
"from langchain_community.llms import GPT4All\n",
|
"from langchain_community.llms import GPT4All\n",
|
||||||
"\n",
|
"\n",
|
||||||
"model = GPT4All(model=\"./models/gpt4all-model.bin\", n_ctx=512, n_threads=8)\n",
|
"model = GPT4All(model=\"./models/gpt4all-model.bin\", n_ctx=512, n_threads=8)\n",
|
||||||
|
"callbacks = [PromptLayerCallbackHandler(pl_tags=[\"langchain\", \"gpt4all\"])]\n",
|
||||||
"\n",
|
"\n",
|
||||||
"response = model(\n",
|
"response = model.invoke(\n",
|
||||||
" \"Once upon a time, \",\n",
|
" \"Once upon a time, \",\n",
|
||||||
" callbacks=[PromptLayerCallbackHandler(pl_tags=[\"langchain\", \"gpt4all\"])],\n",
|
" config={\"callbacks\": callbacks},\n",
|
||||||
")"
|
")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -181,7 +182,7 @@
|
|||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"example_prompt = promptlayer.prompts.get(\"example\", version=1, langchain=True)\n",
|
"example_prompt = promptlayer.prompts.get(\"example\", version=1, langchain=True)\n",
|
||||||
"openai_llm(example_prompt.format(product=\"toasters\"))"
|
"openai_llm.invoke(example_prompt.format(product=\"toasters\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -315,7 +315,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"chat_res = chat_llm(\n",
|
"chat_res = chat_llm.invoke(\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" SystemMessage(content=\"Every answer of yours must be about OpenAI.\"),\n",
|
" SystemMessage(content=\"Every answer of yours must be about OpenAI.\"),\n",
|
||||||
" HumanMessage(content=\"Tell me a joke\"),\n",
|
" HumanMessage(content=\"Tell me a joke\"),\n",
|
||||||
|
@ -72,7 +72,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"output = chat([HumanMessage(content=\"write a funny joke\")])\n",
|
"output = chat.invoke([HumanMessage(content=\"write a funny joke\")])\n",
|
||||||
"print(\"output:\", output)"
|
"print(\"output:\", output)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -90,7 +90,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"kwargs = {\"temperature\": 0.8, \"top_p\": 0.8, \"top_k\": 5}\n",
|
"kwargs = {\"temperature\": 0.8, \"top_p\": 0.8, \"top_k\": 5}\n",
|
||||||
"output = chat([HumanMessage(content=\"write a funny joke\")], **kwargs)\n",
|
"output = chat.invoke([HumanMessage(content=\"write a funny joke\")], **kwargs)\n",
|
||||||
"print(\"output:\", output)"
|
"print(\"output:\", output)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
"messages = [system_message, user_message]\n",
|
"messages = [system_message, user_message]\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# chat with wasm-chat service\n",
|
"# chat with wasm-chat service\n",
|
||||||
"response = chat(messages)\n",
|
"response = chat.invoke(messages)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(f\"[Bot] {response.content}\")"
|
"print(f\"[Bot] {response.content}\")"
|
||||||
]
|
]
|
||||||
|
@ -119,7 +119,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"response = chat(messages)\n",
|
"response = chat.invoke(messages)\n",
|
||||||
"print(response.content) # Displays the AI-generated poem"
|
"print(response.content) # Displays the AI-generated poem"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -147,7 +147,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"@ray.remote(num_cpus=0.1)\n",
|
"@ray.remote(num_cpus=0.1)\n",
|
||||||
"def send_query(llm, prompt):\n",
|
"def send_query(llm, prompt):\n",
|
||||||
" resp = llm(prompt)\n",
|
" resp = llm.invoke(prompt)\n",
|
||||||
" return resp\n",
|
" return resp\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -96,7 +96,7 @@
|
|||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(\n",
|
"print(\n",
|
||||||
" llm(\n",
|
" llm.invoke(\n",
|
||||||
" '<|system|>Enter RP mode. You are Ayumu \"Osaka\" Kasuga.<|user|>Hey Osaka. Tell me about yourself.<|model|>'\n",
|
" '<|system|>Enter RP mode. You are Ayumu \"Osaka\" Kasuga.<|user|>Hey Osaka. Tell me about yourself.<|model|>'\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
")"
|
")"
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
"# Load the model\n",
|
"# Load the model\n",
|
||||||
"llm = BaichuanLLM()\n",
|
"llm = BaichuanLLM()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"res = llm(\"What's your name?\")\n",
|
"res = llm.invoke(\"What's your name?\")\n",
|
||||||
"print(res)"
|
"print(res)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -80,7 +80,7 @@
|
|||||||
"os.environ[\"QIANFAN_SK\"] = \"your_sk\"\n",
|
"os.environ[\"QIANFAN_SK\"] = \"your_sk\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"llm = QianfanLLMEndpoint(streaming=True)\n",
|
"llm = QianfanLLMEndpoint(streaming=True)\n",
|
||||||
"res = llm(\"hi\")\n",
|
"res = llm.invoke(\"hi\")\n",
|
||||||
"print(res)"
|
"print(res)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -185,7 +185,7 @@
|
|||||||
" model=\"ERNIE-Bot-turbo\",\n",
|
" model=\"ERNIE-Bot-turbo\",\n",
|
||||||
" endpoint=\"eb-instant\",\n",
|
" endpoint=\"eb-instant\",\n",
|
||||||
")\n",
|
")\n",
|
||||||
"res = llm(\"hi\")"
|
"res = llm.invoke(\"hi\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
" } \"\"\"\n",
|
" } \"\"\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"multi_response_llm = NIBittensorLLM(top_responses=10)\n",
|
"multi_response_llm = NIBittensorLLM(top_responses=10)\n",
|
||||||
"multi_resp = multi_response_llm(\"What is Neural Network Feeding Mechanism?\")\n",
|
"multi_resp = multi_response_llm.invoke(\"What is Neural Network Feeding Mechanism?\")\n",
|
||||||
"json_multi_resp = json.loads(multi_resp)\n",
|
"json_multi_resp = json.loads(multi_resp)\n",
|
||||||
"pprint(json_multi_resp)"
|
"pprint(json_multi_resp)"
|
||||||
]
|
]
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(llm(\"AI is going to\"))"
|
"print(llm.invoke(\"AI is going to\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -85,7 +85,7 @@
|
|||||||
" model=\"marella/gpt-2-ggml\", callbacks=[StreamingStdOutCallbackHandler()]\n",
|
" model=\"marella/gpt-2-ggml\", callbacks=[StreamingStdOutCallbackHandler()]\n",
|
||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"response = llm(\"AI is going to\")"
|
"response = llm.invoke(\"AI is going to\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -97,7 +97,7 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\n",
|
"print(\n",
|
||||||
" llm(\n",
|
" llm.invoke(\n",
|
||||||
" \"He presented me with plausible evidence for the existence of unicorns: \",\n",
|
" \"He presented me with plausible evidence for the existence of unicorns: \",\n",
|
||||||
" max_length=256,\n",
|
" max_length=256,\n",
|
||||||
" sampling_topk=50,\n",
|
" sampling_topk=50,\n",
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
" model=\"zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base-none\"\n",
|
" model=\"zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base-none\"\n",
|
||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(llm(\"def fib():\"))"
|
"print(llm.invoke(\"def fib():\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -203,7 +203,7 @@
|
|||||||
"User: Answer the following yes/no question by reasoning step by step. Can a dog drive a car?\n",
|
"User: Answer the following yes/no question by reasoning step by step. Can a dog drive a car?\n",
|
||||||
"Assistant:\n",
|
"Assistant:\n",
|
||||||
"\"\"\"\n",
|
"\"\"\"\n",
|
||||||
"print(llm(prompt))"
|
"print(llm.invoke(prompt))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -359,7 +359,7 @@
|
|||||||
"}\n",
|
"}\n",
|
||||||
"message = HumanMessage(content=[text_message, image_message])\n",
|
"message = HumanMessage(content=[text_message, image_message])\n",
|
||||||
"\n",
|
"\n",
|
||||||
"output = llm([message])\n",
|
"output = llm.invoke([message])\n",
|
||||||
"print(output.content)"
|
"print(output.content)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -432,7 +432,7 @@
|
|||||||
"}\n",
|
"}\n",
|
||||||
"message = HumanMessage(content=[text_message, image_message])\n",
|
"message = HumanMessage(content=[text_message, image_message])\n",
|
||||||
"\n",
|
"\n",
|
||||||
"output = llm([message])\n",
|
"output = llm.invoke([message])\n",
|
||||||
"print(output.content)"
|
"print(output.content)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -457,7 +457,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"message2 = HumanMessage(content=\"And where the image is taken?\")\n",
|
"message2 = HumanMessage(content=\"And where the image is taken?\")\n",
|
||||||
"output2 = llm([message, output, message2])\n",
|
"output2 = llm.invoke([message, output, message2])\n",
|
||||||
"print(output2.content)"
|
"print(output2.content)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -486,7 +486,7 @@
|
|||||||
"}\n",
|
"}\n",
|
||||||
"message = HumanMessage(content=[text_message, image_message])\n",
|
"message = HumanMessage(content=[text_message, image_message])\n",
|
||||||
"\n",
|
"\n",
|
||||||
"output = llm([message])\n",
|
"output = llm.invoke([message])\n",
|
||||||
"print(output.content)"
|
"print(output.content)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -57,7 +57,9 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"response = llm(\"### Instruction:\\nWhat is the first book of the bible?\\n### Response:\")"
|
"response = llm.invoke(\n",
|
||||||
|
" \"### Instruction:\\nWhat is the first book of the bible?\\n### Response:\"\n",
|
||||||
|
")"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -90,7 +90,7 @@
|
|||||||
"llm = Konko(model=\"mistralai/mistral-7b-v0.1\", temperature=0.1, max_tokens=128)\n",
|
"llm = Konko(model=\"mistralai/mistral-7b-v0.1\", temperature=0.1, max_tokens=128)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"input_ = \"\"\"You are a helpful assistant. Explain Big Bang Theory briefly.\"\"\"\n",
|
"input_ = \"\"\"You are a helpful assistant. Explain Big Bang Theory briefly.\"\"\"\n",
|
||||||
"print(llm(input_))"
|
"print(llm.invoke(input_))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1020,7 +1020,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"%%time\n",
|
"%%time\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(llm(\"Why is the Moon always showing the same side?\"))"
|
"print(llm.invoke(\"Why is the Moon always showing the same side?\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1044,7 +1044,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"%%time\n",
|
"%%time\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(llm(\"Why is the Moon always showing the same side?\"))"
|
"print(llm.invoke(\"Why is the Moon always showing the same side?\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1109,7 +1109,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"%%time\n",
|
"%%time\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(llm(\"Why is the Moon always showing the same side?\"))"
|
"print(llm.invoke(\"Why is the Moon always showing the same side?\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1133,7 +1133,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"%%time\n",
|
"%%time\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(llm(\"How come we always see one face of the moon?\"))"
|
"print(llm.invoke(\"How come we always see one face of the moon?\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1238,7 +1238,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"%%time\n",
|
"%%time\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(llm(\"Is a true fakery the same as a fake truth?\"))"
|
"print(llm.invoke(\"Is a true fakery the same as a fake truth?\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1262,7 +1262,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"%%time\n",
|
"%%time\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(llm(\"Is a true fakery the same as a fake truth?\"))"
|
"print(llm.invoke(\"Is a true fakery the same as a fake truth?\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1327,7 +1327,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"%%time\n",
|
"%%time\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(llm(\"Are there truths that are false?\"))"
|
"print(llm.invoke(\"Are there truths that are false?\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1351,7 +1351,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"%%time\n",
|
"%%time\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(llm(\"Is is possible that something false can be also true?\"))"
|
"print(llm.invoke(\"Is is possible that something false can be also true?\"))"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -96,7 +96,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"response = model(\"Can you recommend me a nice dry wine?\")\n",
|
"response = model.invoke(\"Can you recommend me a nice dry wine?\")\n",
|
||||||
"print(response)"
|
"print(response)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -269,7 +269,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# response = model(\"Can you help categorize the following emails into positive, negative, and neutral?\")"
|
"# response = model.invoke(\"Can you help categorize the following emails into positive, negative, and neutral?\")"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -323,7 +323,7 @@
|
|||||||
"User: Answer the following yes/no question by reasoning step by step. Can a dog drive a car?\n",
|
"User: Answer the following yes/no question by reasoning step by step. Can a dog drive a car?\n",
|
||||||
"Assistant:\n",
|
"Assistant:\n",
|
||||||
"\"\"\"\n",
|
"\"\"\"\n",
|
||||||
"_ = llm(prompt)"
|
"_ = llm.invoke(prompt)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -376,13 +376,13 @@
|
|||||||
"Assistant:\n",
|
"Assistant:\n",
|
||||||
"\"\"\"\n",
|
"\"\"\"\n",
|
||||||
"start_time = time.perf_counter()\n",
|
"start_time = time.perf_counter()\n",
|
||||||
"raw_output = llm(prompt) # raw output, no stop\n",
|
"raw_output = llm.invoke(prompt) # raw output, no stop\n",
|
||||||
"end_time = time.perf_counter()\n",
|
"end_time = time.perf_counter()\n",
|
||||||
"print(f\"Raw output:\\n {raw_output}\")\n",
|
"print(f\"Raw output:\\n {raw_output}\")\n",
|
||||||
"print(f\"Raw output runtime: {end_time - start_time} seconds\")\n",
|
"print(f\"Raw output runtime: {end_time - start_time} seconds\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"start_time = time.perf_counter()\n",
|
"start_time = time.perf_counter()\n",
|
||||||
"stopped_output = llm(prompt, stop=[\"\\n\\n\"]) # stop on double newlines\n",
|
"stopped_output = llm.invoke(prompt, stop=[\"\\n\\n\"]) # stop on double newlines\n",
|
||||||
"end_time = time.perf_counter()\n",
|
"end_time = time.perf_counter()\n",
|
||||||
"print(f\"Stopped output:\\n {stopped_output}\")\n",
|
"print(f\"Stopped output:\\n {stopped_output}\")\n",
|
||||||
"print(f\"Stopped output runtime: {end_time - start_time} seconds\")"
|
"print(f\"Stopped output runtime: {end_time - start_time} seconds\")"
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
"# Load the model\n",
|
"# Load the model\n",
|
||||||
"llm = SparkLLM()\n",
|
"llm = SparkLLM()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"res = llm(\"What's your name?\")\n",
|
"res = llm.invoke(\"What's your name?\")\n",
|
||||||
"print(res)"
|
"print(res)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -23,7 +23,7 @@ It provides a unified interface for all models:
|
|||||||
```python
|
```python
|
||||||
llm = CTransformers(model='/path/to/ggml-gpt-2.bin', model_type='gpt2')
|
llm = CTransformers(model='/path/to/ggml-gpt-2.bin', model_type='gpt2')
|
||||||
|
|
||||||
print(llm('AI is going to'))
|
print(llm.invoke('AI is going to'))
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are getting `illegal instruction` error, try using `lib='avx'` or `lib='basic'`:
|
If you are getting `illegal instruction` error, try using `lib='avx'` or `lib='basic'`:
|
||||||
|
@ -22,7 +22,7 @@ It provides a unified interface for all models:
|
|||||||
```python
|
```python
|
||||||
llm = DeepSparse(model='zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base-none')
|
llm = DeepSparse(model='zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base-none')
|
||||||
|
|
||||||
print(llm('def fib():'))
|
print(llm.invoke('def fib():'))
|
||||||
```
|
```
|
||||||
|
|
||||||
Additional parameters can be passed using the `config` parameter:
|
Additional parameters can be passed using the `config` parameter:
|
||||||
|
@ -83,7 +83,7 @@ def langchain_llm() -> str:
|
|||||||
temperature=0.2,
|
temperature=0.2,
|
||||||
callbacks=[FlyteCallbackHandler()],
|
callbacks=[FlyteCallbackHandler()],
|
||||||
)
|
)
|
||||||
return llm([HumanMessage(content="Tell me a joke")]).content
|
return llm.invoke([HumanMessage(content="Tell me a joke")]).content
|
||||||
```
|
```
|
||||||
|
|
||||||
### Chain
|
### Chain
|
||||||
|
@ -27,7 +27,7 @@ from langchain_community.llms import GPT4All
|
|||||||
model = GPT4All(model="./models/mistral-7b-openorca.Q4_0.gguf", n_threads=8)
|
model = GPT4All(model="./models/mistral-7b-openorca.Q4_0.gguf", n_threads=8)
|
||||||
|
|
||||||
# Generate text
|
# Generate text
|
||||||
response = model("Once upon a time, ")
|
response = model.invoke("Once upon a time, ")
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also customize the generation parameters, such as n_predict, temp, top_p, top_k, and others.
|
You can also customize the generation parameters, such as n_predict, temp, top_p, top_k, and others.
|
||||||
|
@ -29,7 +29,7 @@ openai.api_base = "https://oai.hconeai.com/v1"
|
|||||||
|
|
||||||
llm = OpenAI(temperature=0.9, headers={"Helicone-Cache-Enabled": "true"})
|
llm = OpenAI(temperature=0.9, headers={"Helicone-Cache-Enabled": "true"})
|
||||||
text = "What is a helicone?"
|
text = "What is a helicone?"
|
||||||
print(llm(text))
|
print(llm.invoke(text))
|
||||||
```
|
```
|
||||||
|
|
||||||
[Helicone caching docs](https://docs.helicone.ai/advanced-usage/caching)
|
[Helicone caching docs](https://docs.helicone.ai/advanced-usage/caching)
|
||||||
@ -47,7 +47,7 @@ llm = OpenAI(temperature=0.9, headers={
|
|||||||
"Helicone-Property-App": "mobile",
|
"Helicone-Property-App": "mobile",
|
||||||
})
|
})
|
||||||
text = "What is a helicone?"
|
text = "What is a helicone?"
|
||||||
print(llm(text))
|
print(llm.invoke(text))
|
||||||
```
|
```
|
||||||
|
|
||||||
[Helicone property docs](https://docs.helicone.ai/advanced-usage/custom-properties)
|
[Helicone property docs](https://docs.helicone.ai/advanced-usage/custom-properties)
|
||||||
|
@ -44,7 +44,7 @@ See a usage [example](/docs/integrations/llms/konko).
|
|||||||
from langchain.llms import Konko
|
from langchain.llms import Konko
|
||||||
llm = Konko(max_tokens=800, model='mistralai/Mistral-7B-v0.1')
|
llm = Konko(max_tokens=800, model='mistralai/Mistral-7B-v0.1')
|
||||||
prompt = "Generate a Product Description for Apple Iphone 15"
|
prompt = "Generate a Product Description for Apple Iphone 15"
|
||||||
response = llm(prompt)
|
response = llm.invoke(prompt)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Chat Models
|
## Chat Models
|
||||||
|
@ -23,7 +23,7 @@ model = Predibase(
|
|||||||
predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)
|
predibase_sdk_version=None, # optional parameter (defaults to the latest Predibase SDK version if omitted)
|
||||||
)
|
)
|
||||||
|
|
||||||
response = model("Can you recommend me a nice dry wine?")
|
response = model.invoke("Can you recommend me a nice dry wine?")
|
||||||
print(response)
|
print(response)
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ model = Predibase(
|
|||||||
adapter_version=1,
|
adapter_version=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = model("Can you recommend me a nice dry wine?")
|
response = model.invoke("Can you recommend me a nice dry wine?")
|
||||||
print(response)
|
print(response)
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -64,6 +64,6 @@ model = Predibase(
|
|||||||
adapter_id="predibase/e2e_nlg",
|
adapter_id="predibase/e2e_nlg",
|
||||||
)
|
)
|
||||||
|
|
||||||
response = model("Can you recommend me a nice dry wine?")
|
response = model.invoke("Can you recommend me a nice dry wine?")
|
||||||
print(response)
|
print(response)
|
||||||
```
|
```
|
||||||
|
@ -44,7 +44,7 @@ def generate_prompt(instruction, input=None):
|
|||||||
|
|
||||||
|
|
||||||
model = RWKV(model="./models/RWKV-4-Raven-3B-v7-Eng-20230404-ctx4096.pth", strategy="cpu fp32", tokens_path="./rwkv/20B_tokenizer.json")
|
model = RWKV(model="./models/RWKV-4-Raven-3B-v7-Eng-20230404-ctx4096.pth", strategy="cpu fp32", tokens_path="./rwkv/20B_tokenizer.json")
|
||||||
response = model(generate_prompt("Once upon a time, "))
|
response = model.invoke(generate_prompt("Once upon a time, "))
|
||||||
```
|
```
|
||||||
## Model File
|
## Model File
|
||||||
|
|
||||||
|
@ -545,7 +545,7 @@
|
|||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"_input = prompt.format_prompt(text=dataset[0][\"text\"])\n",
|
"_input = prompt.format_prompt(text=dataset[0][\"text\"])\n",
|
||||||
"output = llm(_input.to_string())\n",
|
"output = llm.invoke(_input.to_string())\n",
|
||||||
"\n",
|
"\n",
|
||||||
"parsed = parser.parse(output)\n",
|
"parsed = parser.parse(output)\n",
|
||||||
"parsed"
|
"parsed"
|
||||||
|
@ -1115,7 +1115,8 @@ class CassandraCache(BaseCache):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
A wrapper around `delete` with the LLM being passed.
|
A wrapper around `delete` with the LLM being passed.
|
||||||
In case the llm(prompt) calls have a `stop` param, you should pass it here
|
In case the llm.invoke(prompt) calls have a `stop` param, you should
|
||||||
|
pass it here
|
||||||
"""
|
"""
|
||||||
llm_string = get_prompts(
|
llm_string = get_prompts(
|
||||||
{**llm.dict(), **{"stop": stop}},
|
{**llm.dict(), **{"stop": stop}},
|
||||||
@ -1505,7 +1506,8 @@ class AstraDBCache(BaseCache):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
A wrapper around `delete` with the LLM being passed.
|
A wrapper around `delete` with the LLM being passed.
|
||||||
In case the llm(prompt) calls have a `stop` param, you should pass it here
|
In case the llm.invoke(prompt) calls have a `stop` param, you should
|
||||||
|
pass it here
|
||||||
"""
|
"""
|
||||||
llm_string = get_prompts(
|
llm_string = get_prompts(
|
||||||
{**llm.dict(), **{"stop": stop}},
|
{**llm.dict(), **{"stop": stop}},
|
||||||
@ -1518,7 +1520,8 @@ class AstraDBCache(BaseCache):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
A wrapper around `adelete` with the LLM being passed.
|
A wrapper around `adelete` with the LLM being passed.
|
||||||
In case the llm(prompt) calls have a `stop` param, you should pass it here
|
In case the llm.invoke(prompt) calls have a `stop` param, you should
|
||||||
|
pass it here
|
||||||
"""
|
"""
|
||||||
llm_string = (
|
llm_string = (
|
||||||
await aget_prompts(
|
await aget_prompts(
|
||||||
|
@ -58,7 +58,7 @@ class ContextCallbackHandler(BaseCallbackHandler):
|
|||||||
... SystemMessage(content="You translate English to French."),
|
... SystemMessage(content="You translate English to French."),
|
||||||
... HumanMessage(content="I love programming with LangChain."),
|
... HumanMessage(content="I love programming with LangChain."),
|
||||||
... ]
|
... ]
|
||||||
>>> chat(messages)
|
>>> chat.invoke(messages)
|
||||||
|
|
||||||
Chain Example:
|
Chain Example:
|
||||||
>>> from langchain.chains import LLMChain
|
>>> from langchain.chains import LLMChain
|
||||||
|
@ -263,7 +263,7 @@ class AzureMLChatOnlineEndpoint(BaseChatModel, AzureMLBaseEndpoint):
|
|||||||
The string generated by the model.
|
The string generated by the model.
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
response = azureml_model("Tell me a joke.")
|
response = azureml_model.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
_model_kwargs = self.model_kwargs or {}
|
_model_kwargs = self.model_kwargs or {}
|
||||||
_model_kwargs.update(kwargs)
|
_model_kwargs.update(kwargs)
|
||||||
|
@ -250,7 +250,7 @@ class QianfanChatEndpoint(BaseChatModel):
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
response = qianfan_model("Tell me a joke.")
|
response = qianfan_model.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
completion = ""
|
completion = ""
|
||||||
|
@ -284,4 +284,4 @@ class AlephAlpha(LLM):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
aa = AlephAlpha()
|
aa = AlephAlpha()
|
||||||
|
|
||||||
print(aa("How are you?")) # noqa: T201
|
print(aa.invoke("How are you?")) # noqa: T201
|
||||||
|
@ -170,13 +170,13 @@ class Anthropic(LLM, _AnthropicCommon):
|
|||||||
|
|
||||||
# Simplest invocation, automatically wrapped with HUMAN_PROMPT
|
# Simplest invocation, automatically wrapped with HUMAN_PROMPT
|
||||||
# and AI_PROMPT.
|
# and AI_PROMPT.
|
||||||
response = model("What are the biggest risks facing humanity?")
|
response = model.invoke("What are the biggest risks facing humanity?")
|
||||||
|
|
||||||
# Or if you want to use the chat mode, build a few-shot-prompt, or
|
# Or if you want to use the chat mode, build a few-shot-prompt, or
|
||||||
# put words in the Assistant's mouth, use HUMAN_PROMPT and AI_PROMPT:
|
# put words in the Assistant's mouth, use HUMAN_PROMPT and AI_PROMPT:
|
||||||
raw_prompt = "What are the biggest risks facing humanity?"
|
raw_prompt = "What are the biggest risks facing humanity?"
|
||||||
prompt = f"{anthropic.HUMAN_PROMPT} {prompt}{anthropic.AI_PROMPT}"
|
prompt = f"{anthropic.HUMAN_PROMPT} {prompt}{anthropic.AI_PROMPT}"
|
||||||
response = model(prompt)
|
response = model.invoke(prompt)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -236,7 +236,7 @@ class Anthropic(LLM, _AnthropicCommon):
|
|||||||
|
|
||||||
prompt = "What are the biggest risks facing humanity?"
|
prompt = "What are the biggest risks facing humanity?"
|
||||||
prompt = f"\n\nHuman: {prompt}\n\nAssistant:"
|
prompt = f"\n\nHuman: {prompt}\n\nAssistant:"
|
||||||
response = model(prompt)
|
response = model.invoke(prompt)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
|
@ -75,7 +75,7 @@ class Anyscale(BaseOpenAI):
|
|||||||
# To leverage Ray for parallel processing
|
# To leverage Ray for parallel processing
|
||||||
@ray.remote(num_cpus=1)
|
@ray.remote(num_cpus=1)
|
||||||
def send_query(llm, text):
|
def send_query(llm, text):
|
||||||
resp = llm(text)
|
resp = llm.invoke(text)
|
||||||
return resp
|
return resp
|
||||||
futures = [send_query.remote(anyscalellm, text) for text in texts]
|
futures = [send_query.remote(anyscalellm, text) for text in texts]
|
||||||
results = ray.get(futures)
|
results = ray.get(futures)
|
||||||
|
@ -528,7 +528,7 @@ class AzureMLOnlineEndpoint(BaseLLM, AzureMLBaseEndpoint):
|
|||||||
The string generated by the model.
|
The string generated by the model.
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
response = azureml_model("Tell me a joke.")
|
response = azureml_model.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
_model_kwargs = self.model_kwargs or {}
|
_model_kwargs = self.model_kwargs or {}
|
||||||
_model_kwargs.update(kwargs)
|
_model_kwargs.update(kwargs)
|
||||||
|
@ -172,7 +172,7 @@ class QianfanLLMEndpoint(LLM):
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
response = qianfan_model("Tell me a joke.")
|
response = qianfan_model.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
completion = ""
|
completion = ""
|
||||||
|
@ -829,7 +829,7 @@ class Bedrock(LLM, BedrockBase):
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
response = llm("Tell me a joke.")
|
response = llm.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
|
@ -72,7 +72,7 @@ class ChatGLM(LLM):
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
response = chatglm_llm("Who are you?")
|
response = chatglm_llm.invoke("Who are you?")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_model_kwargs = self.model_kwargs or {}
|
_model_kwargs = self.model_kwargs or {}
|
||||||
|
@ -106,7 +106,7 @@ class ChatGLM3(LLM):
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
response = chatglm_llm("Who are you?")
|
response = chatglm_llm.invoke("Who are you?")
|
||||||
"""
|
"""
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ class Clarifai(LLM):
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
response = clarifai_llm("Tell me a joke.")
|
response = clarifai_llm.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -97,7 +97,7 @@ class CTransformers(LLM):
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
response = llm("Tell me a joke.")
|
response = llm.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
text = []
|
text = []
|
||||||
_run_manager = run_manager or CallbackManagerForLLMRun.get_noop_manager()
|
_run_manager = run_manager or CallbackManagerForLLMRun.get_noop_manager()
|
||||||
@ -125,7 +125,7 @@ class CTransformers(LLM):
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
response = llm("Once upon a time, ")
|
response = llm.invoke("Once upon a time, ")
|
||||||
"""
|
"""
|
||||||
text_callback = None
|
text_callback = None
|
||||||
if run_manager:
|
if run_manager:
|
||||||
|
@ -92,7 +92,7 @@ class DeepSparse(LLM):
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
from langchain_community.llms import DeepSparse
|
from langchain_community.llms import DeepSparse
|
||||||
llm = DeepSparse(model="zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base_quant-none")
|
llm = DeepSparse(model="zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base_quant-none")
|
||||||
llm("Tell me a joke.")
|
llm.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
combined_output = ""
|
combined_output = ""
|
||||||
@ -130,7 +130,7 @@ class DeepSparse(LLM):
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
from langchain_community.llms import DeepSparse
|
from langchain_community.llms import DeepSparse
|
||||||
llm = DeepSparse(model="zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base_quant-none")
|
llm = DeepSparse(model="zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base_quant-none")
|
||||||
llm("Tell me a joke.")
|
llm.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
combined_output = ""
|
combined_output = ""
|
||||||
|
@ -21,7 +21,7 @@ class GPT4All(LLM):
|
|||||||
model = GPT4All(model="./models/gpt4all-model.bin", n_threads=8)
|
model = GPT4All(model="./models/gpt4all-model.bin", n_threads=8)
|
||||||
|
|
||||||
# Simplest invocation
|
# Simplest invocation
|
||||||
response = model("Once upon a time, ")
|
response = model.invoke("Once upon a time, ")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model: str
|
model: str
|
||||||
@ -197,7 +197,7 @@ class GPT4All(LLM):
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
prompt = "Once upon a time, "
|
prompt = "Once upon a time, "
|
||||||
response = model(prompt, n_predict=55)
|
response = model.invoke(prompt, n_predict=55)
|
||||||
"""
|
"""
|
||||||
text_callback = None
|
text_callback = None
|
||||||
if run_manager:
|
if run_manager:
|
||||||
|
@ -43,7 +43,7 @@ class HuggingFaceEndpoint(LLM):
|
|||||||
repetition_penalty=1.03,
|
repetition_penalty=1.03,
|
||||||
huggingfacehub_api_token="my-api-key"
|
huggingfacehub_api_token="my-api-key"
|
||||||
)
|
)
|
||||||
print(llm("What is Deep Learning?"))
|
print(llm.invoke("What is Deep Learning?"))
|
||||||
|
|
||||||
# Streaming response example
|
# Streaming response example
|
||||||
from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
||||||
@ -61,7 +61,7 @@ class HuggingFaceEndpoint(LLM):
|
|||||||
streaming=True,
|
streaming=True,
|
||||||
huggingfacehub_api_token="my-api-key"
|
huggingfacehub_api_token="my-api-key"
|
||||||
)
|
)
|
||||||
print(llm("What is Deep Learning?"))
|
print(llm.invoke("What is Deep Learning?"))
|
||||||
|
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class HuggingFaceTextGenInference(LLM):
|
|||||||
temperature=0.01,
|
temperature=0.01,
|
||||||
repetition_penalty=1.03,
|
repetition_penalty=1.03,
|
||||||
)
|
)
|
||||||
print(llm("What is Deep Learning?")) # noqa: T201
|
print(llm.invoke("What is Deep Learning?")) # noqa: T201
|
||||||
|
|
||||||
# Streaming response example
|
# Streaming response example
|
||||||
from langchain_community.callbacks import streaming_stdout
|
from langchain_community.callbacks import streaming_stdout
|
||||||
@ -53,7 +53,7 @@ class HuggingFaceTextGenInference(LLM):
|
|||||||
callbacks=callbacks,
|
callbacks=callbacks,
|
||||||
streaming=True
|
streaming=True
|
||||||
)
|
)
|
||||||
print(llm("What is Deep Learning?")) # noqa: T201
|
print(llm.invoke("What is Deep Learning?")) # noqa: T201
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ class KoboldApiLLM(LLM):
|
|||||||
from langchain_community.llms import KoboldApiLLM
|
from langchain_community.llms import KoboldApiLLM
|
||||||
|
|
||||||
llm = KoboldApiLLM(endpoint="http://localhost:5000")
|
llm = KoboldApiLLM(endpoint="http://localhost:5000")
|
||||||
llm("Write a story about dragons.")
|
llm.invoke("Write a story about dragons.")
|
||||||
"""
|
"""
|
||||||
data: Dict[str, Any] = {
|
data: Dict[str, Any] = {
|
||||||
"prompt": prompt,
|
"prompt": prompt,
|
||||||
|
@ -278,7 +278,7 @@ class LlamaCpp(LLM):
|
|||||||
|
|
||||||
from langchain_community.llms import LlamaCpp
|
from langchain_community.llms import LlamaCpp
|
||||||
llm = LlamaCpp(model_path="/path/to/local/llama/model.bin")
|
llm = LlamaCpp(model_path="/path/to/local/llama/model.bin")
|
||||||
llm("This is a prompt.")
|
llm.invoke("This is a prompt.")
|
||||||
"""
|
"""
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
# If streaming is enabled, we use the stream
|
# If streaming is enabled, we use the stream
|
||||||
|
@ -115,7 +115,7 @@ class MosaicML(LLM):
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
response = mosaic_llm("Tell me a joke.")
|
response = mosaic_llm.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
_model_kwargs = self.model_kwargs or {}
|
_model_kwargs = self.model_kwargs or {}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ class OpaquePrompts(LLM):
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
response = op_llm("Tell me a joke.")
|
response = op_llm.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
import opaqueprompts as op
|
import opaqueprompts as op
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class OpenLLM(LLM):
|
|||||||
model_name='flan-t5',
|
model_name='flan-t5',
|
||||||
model_id='google/flan-t5-large',
|
model_id='google/flan-t5-large',
|
||||||
)
|
)
|
||||||
llm("What is the difference between a duck and a goose?")
|
llm.invoke("What is the difference between a duck and a goose?")
|
||||||
|
|
||||||
For all available supported models, you can run 'openllm models'.
|
For all available supported models, you can run 'openllm models'.
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ class PredictionGuard(LLM):
|
|||||||
The string generated by the model.
|
The string generated by the model.
|
||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
response = pgllm("Tell me a joke.")
|
response = pgllm.invoke("Tell me a joke.")
|
||||||
"""
|
"""
|
||||||
import predictionguard as pg
|
import predictionguard as pg
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class RWKV(LLM, BaseModel):
|
|||||||
model = RWKV(model="./models/rwkv-3b-fp16.bin", strategy="cpu fp32")
|
model = RWKV(model="./models/rwkv-3b-fp16.bin", strategy="cpu fp32")
|
||||||
|
|
||||||
# Simplest invocation
|
# Simplest invocation
|
||||||
response = model("Once upon a time, ")
|
response = model.invoke("Once upon a time, ")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model: str
|
model: str
|
||||||
@ -225,7 +225,7 @@ class RWKV(LLM, BaseModel):
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
prompt = "Once upon a time, "
|
prompt = "Once upon a time, "
|
||||||
response = model(prompt, n_predict=55)
|
response = model.invoke(prompt, n_predict=55)
|
||||||
"""
|
"""
|
||||||
text = self.rwkv_generate(prompt)
|
text = self.rwkv_generate(prompt)
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ class TextGen(LLM):
|
|||||||
|
|
||||||
from langchain_community.llms import TextGen
|
from langchain_community.llms import TextGen
|
||||||
llm = TextGen(model_url="http://localhost:5000")
|
llm = TextGen(model_url="http://localhost:5000")
|
||||||
llm("Write a story about llamas.")
|
llm.invoke("Write a story about llamas.")
|
||||||
"""
|
"""
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
combined_text_output = ""
|
combined_text_output = ""
|
||||||
@ -245,7 +245,7 @@ class TextGen(LLM):
|
|||||||
|
|
||||||
from langchain_community.llms import TextGen
|
from langchain_community.llms import TextGen
|
||||||
llm = TextGen(model_url="http://localhost:5000")
|
llm = TextGen(model_url="http://localhost:5000")
|
||||||
llm("Write a story about llamas.")
|
llm.invoke("Write a story about llamas.")
|
||||||
"""
|
"""
|
||||||
if self.streaming:
|
if self.streaming:
|
||||||
combined_text_output = ""
|
combined_text_output = ""
|
||||||
|
@ -320,7 +320,7 @@ class WatsonxLLM(BaseLLM):
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
response = watsonx_llm("What is a molecule")
|
response = watsonx_llm.invoke("What is a molecule")
|
||||||
"""
|
"""
|
||||||
result = self._generate(
|
result = self._generate(
|
||||||
prompts=[prompt], stop=stop, run_manager=run_manager, **kwargs
|
prompts=[prompt], stop=stop, run_manager=run_manager, **kwargs
|
||||||
|
@ -222,7 +222,7 @@ class WeightOnlyQuantPipeline(LLM):
|
|||||||
model_id="google/flan-t5-large",
|
model_id="google/flan-t5-large",
|
||||||
task="text2text-generation",
|
task="text2text-generation",
|
||||||
)
|
)
|
||||||
llm("This is a prompt.")
|
llm.invoke("This is a prompt.")
|
||||||
"""
|
"""
|
||||||
response = self.pipeline(prompt)
|
response = self.pipeline(prompt)
|
||||||
if self.pipeline.task == "text-generation":
|
if self.pipeline.task == "text-generation":
|
||||||
|
@ -62,7 +62,7 @@ class Xinference(LLM):
|
|||||||
model_uid = {model_uid} # replace model_uid with the model UID return from launching the model
|
model_uid = {model_uid} # replace model_uid with the model UID return from launching the model
|
||||||
)
|
)
|
||||||
|
|
||||||
llm(
|
llm.invoke(
|
||||||
prompt="Q: where can we visit in the capital of France? A:",
|
prompt="Q: where can we visit in the capital of France? A:",
|
||||||
generate_config={"max_tokens": 1024, "stream": True},
|
generate_config={"max_tokens": 1024, "stream": True},
|
||||||
)
|
)
|
||||||
|
@ -26,7 +26,7 @@ class Yuan2(LLM):
|
|||||||
top_k=40,
|
top_k=40,
|
||||||
)
|
)
|
||||||
print(yuan_llm)
|
print(yuan_llm)
|
||||||
print(yuan_llm("你是谁?"))
|
print(yuan_llm.invoke("你是谁?"))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
infer_api: str = "http://127.0.0.1:8000/yuan"
|
infer_api: str = "http://127.0.0.1:8000/yuan"
|
||||||
@ -137,7 +137,7 @@ class Yuan2(LLM):
|
|||||||
Example:
|
Example:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
response = yuan_llm("你能做什么?")
|
response = yuan_llm.invoke("你能做什么?")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.use_history:
|
if self.use_history:
|
||||||
|
@ -9,14 +9,14 @@ from langchain_community.llms import OpenAI
|
|||||||
async def test_openai_callback() -> None:
|
async def test_openai_callback() -> None:
|
||||||
llm = OpenAI(temperature=0)
|
llm = OpenAI(temperature=0)
|
||||||
with get_openai_callback() as cb:
|
with get_openai_callback() as cb:
|
||||||
llm("What is the square root of 4?")
|
llm.invoke("What is the square root of 4?")
|
||||||
|
|
||||||
total_tokens = cb.total_tokens
|
total_tokens = cb.total_tokens
|
||||||
assert total_tokens > 0
|
assert total_tokens > 0
|
||||||
|
|
||||||
with get_openai_callback() as cb:
|
with get_openai_callback() as cb:
|
||||||
llm("What is the square root of 4?")
|
llm.invoke("What is the square root of 4?")
|
||||||
llm("What is the square root of 4?")
|
llm.invoke("What is the square root of 4?")
|
||||||
|
|
||||||
assert cb.total_tokens == total_tokens * 2
|
assert cb.total_tokens == total_tokens * 2
|
||||||
|
|
||||||
@ -44,8 +44,8 @@ def test_openai_callback_batch_llm() -> None:
|
|||||||
total_tokens = cb.total_tokens
|
total_tokens = cb.total_tokens
|
||||||
|
|
||||||
with get_openai_callback() as cb:
|
with get_openai_callback() as cb:
|
||||||
llm("What is the square root of 4?")
|
llm.invoke("What is the square root of 4?")
|
||||||
llm("What is the square root of 4?")
|
llm.invoke("What is the square root of 4?")
|
||||||
|
|
||||||
assert cb.total_tokens == total_tokens
|
assert cb.total_tokens == total_tokens
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ def test_anthropic_call() -> None:
|
|||||||
"""Test valid call to anthropic."""
|
"""Test valid call to anthropic."""
|
||||||
chat = ChatAnthropic(model="test")
|
chat = ChatAnthropic(model="test")
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ def test_anthropic_streaming() -> None:
|
|||||||
"""Test streaming tokens from anthropic."""
|
"""Test streaming tokens from anthropic."""
|
||||||
chat = ChatAnthropic(model="test", streaming=True)
|
chat = ChatAnthropic(model="test", streaming=True)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ def test_anthropic_streaming_callback() -> None:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Write me a sentence with 10 words.")
|
message = HumanMessage(content="Write me a sentence with 10 words.")
|
||||||
chat([message])
|
chat.invoke([message])
|
||||||
assert callback_handler.llm_streams > 1
|
assert callback_handler.llm_streams > 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ def llm() -> AzureChatOpenAI:
|
|||||||
def test_chat_openai(llm: AzureChatOpenAI) -> None:
|
def test_chat_openai(llm: AzureChatOpenAI) -> None:
|
||||||
"""Test AzureChatOpenAI wrapper."""
|
"""Test AzureChatOpenAI wrapper."""
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = llm([message])
|
response = llm.invoke([message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ def test_chat_openai_streaming() -> None:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert callback_handler.llm_streams > 0
|
assert callback_handler.llm_streams > 0
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ from langchain_community.chat_models.baichuan import ChatBaichuan
|
|||||||
def test_chat_baichuan_default() -> None:
|
def test_chat_baichuan_default() -> None:
|
||||||
chat = ChatBaichuan(streaming=True)
|
chat = ChatBaichuan(streaming=True)
|
||||||
message = HumanMessage(content="请完整背诵将进酒,背诵5遍")
|
message = HumanMessage(content="请完整背诵将进酒,背诵5遍")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ def test_chat_baichuan_default() -> None:
|
|||||||
def test_chat_baichuan_default_non_streaming() -> None:
|
def test_chat_baichuan_default_non_streaming() -> None:
|
||||||
chat = ChatBaichuan()
|
chat = ChatBaichuan()
|
||||||
message = HumanMessage(content="请完整背诵将进酒,背诵5遍")
|
message = HumanMessage(content="请完整背诵将进酒,背诵5遍")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ def test_chat_baichuan_default_non_streaming() -> None:
|
|||||||
def test_chat_baichuan_turbo() -> None:
|
def test_chat_baichuan_turbo() -> None:
|
||||||
chat = ChatBaichuan(model="Baichuan2-Turbo", streaming=True)
|
chat = ChatBaichuan(model="Baichuan2-Turbo", streaming=True)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ def test_chat_baichuan_turbo() -> None:
|
|||||||
def test_chat_baichuan_turbo_non_streaming() -> None:
|
def test_chat_baichuan_turbo_non_streaming() -> None:
|
||||||
chat = ChatBaichuan(model="Baichuan2-Turbo")
|
chat = ChatBaichuan(model="Baichuan2-Turbo")
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ def test_chat_baichuan_turbo_non_streaming() -> None:
|
|||||||
def test_chat_baichuan_with_temperature() -> None:
|
def test_chat_baichuan_with_temperature() -> None:
|
||||||
chat = ChatBaichuan(temperature=1.0)
|
chat = ChatBaichuan(temperature=1.0)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -49,7 +49,9 @@ def test_chat_baichuan_with_temperature() -> None:
|
|||||||
def test_chat_baichuan_with_kwargs() -> None:
|
def test_chat_baichuan_with_kwargs() -> None:
|
||||||
chat = ChatBaichuan()
|
chat = ChatBaichuan()
|
||||||
message = HumanMessage(content="百川192K API是什么时候上线的?")
|
message = HumanMessage(content="百川192K API是什么时候上线的?")
|
||||||
response = chat([message], temperature=0.88, top_p=0.7, with_search_enhance=True)
|
response = chat.invoke(
|
||||||
|
[message], temperature=0.88, top_p=0.7, with_search_enhance=True
|
||||||
|
)
|
||||||
print(response) # noqa: T201
|
print(response) # noqa: T201
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
@ -25,7 +25,7 @@ def test_chat_bedrock(chat: BedrockChat) -> None:
|
|||||||
"""Test BedrockChat wrapper."""
|
"""Test BedrockChat wrapper."""
|
||||||
system = SystemMessage(content="You are a helpful assistant.")
|
system = SystemMessage(content="You are a helpful assistant.")
|
||||||
human = HumanMessage(content="Hello")
|
human = HumanMessage(content="Hello")
|
||||||
response = chat([system, human])
|
response = chat.invoke([system, human])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ def test_chat_bedrock_streaming() -> None:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert callback_handler.llm_streams > 0
|
assert callback_handler.llm_streams > 0
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ def test_dappier_chat() -> None:
|
|||||||
dappier_model="dm_01hpsxyfm2fwdt2zet9cg6fdxt",
|
dappier_model="dm_01hpsxyfm2fwdt2zet9cg6fdxt",
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Who are you ?")
|
message = HumanMessage(content="Who are you ?")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ def test_chat_edenai() -> None:
|
|||||||
provider="openai", model="gpt-3.5-turbo", temperature=0, max_tokens=1000
|
provider="openai", model="gpt-3.5-turbo", temperature=0, max_tokens=1000
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Who are you ?")
|
message = HumanMessage(content="Who are you ?")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ from langchain_community.chat_models.ernie import ErnieBotChat
|
|||||||
def test_chat_ernie_bot() -> None:
|
def test_chat_ernie_bot() -> None:
|
||||||
chat = ErnieBotChat()
|
chat = ErnieBotChat()
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ def test_chat_ernie_bot() -> None:
|
|||||||
def test_chat_ernie_bot_with_model_name() -> None:
|
def test_chat_ernie_bot_with_model_name() -> None:
|
||||||
chat = ErnieBotChat(model_name="ERNIE-Bot")
|
chat = ErnieBotChat(model_name="ERNIE-Bot")
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ def test_chat_ernie_bot_with_model_name() -> None:
|
|||||||
def test_chat_ernie_bot_with_temperature() -> None:
|
def test_chat_ernie_bot_with_temperature() -> None:
|
||||||
chat = ErnieBotChat(model_name="ERNIE-Bot", temperature=1.0)
|
chat = ErnieBotChat(model_name="ERNIE-Bot", temperature=1.0)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ def test_chat_ernie_bot_with_temperature() -> None:
|
|||||||
def test_chat_ernie_bot_with_kwargs() -> None:
|
def test_chat_ernie_bot_with_kwargs() -> None:
|
||||||
chat = ErnieBotChat()
|
chat = ErnieBotChat()
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message], temperature=0.88, top_p=0.7)
|
response = chat.invoke([message], temperature=0.88, top_p=0.7)
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ def test_wrong_temperature_1() -> None:
|
|||||||
chat = ErnieBotChat()
|
chat = ErnieBotChat()
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
with pytest.raises(ValueError) as e:
|
with pytest.raises(ValueError) as e:
|
||||||
chat([message], temperature=1.2)
|
chat.invoke([message], temperature=1.2)
|
||||||
assert "parameter check failed, temperature range is (0, 1.0]" in str(e)
|
assert "parameter check failed, temperature range is (0, 1.0]" in str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -54,5 +54,5 @@ def test_wrong_temperature_2() -> None:
|
|||||||
chat = ErnieBotChat()
|
chat = ErnieBotChat()
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
with pytest.raises(ValueError) as e:
|
with pytest.raises(ValueError) as e:
|
||||||
chat([message], temperature=0)
|
chat.invoke([message], temperature=0)
|
||||||
assert "parameter check failed, temperature range is (0, 1.0]" in str(e)
|
assert "parameter check failed, temperature range is (0, 1.0]" in str(e)
|
||||||
|
@ -21,7 +21,7 @@ def chat() -> ChatFireworks:
|
|||||||
def test_chat_fireworks(chat: ChatFireworks) -> None:
|
def test_chat_fireworks(chat: ChatFireworks) -> None:
|
||||||
"""Test ChatFireworks wrapper."""
|
"""Test ChatFireworks wrapper."""
|
||||||
message = HumanMessage(content="What is the weather in Redwood City, CA today")
|
message = HumanMessage(content="What is the weather in Redwood City, CA today")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ def test_chat_fireworks_system_message(chat: ChatFireworks) -> None:
|
|||||||
"""Test ChatFireworks wrapper with system message."""
|
"""Test ChatFireworks wrapper with system message."""
|
||||||
system_message = SystemMessage(content="You are to chat with the user.")
|
system_message = SystemMessage(content="You are to chat with the user.")
|
||||||
human_message = HumanMessage(content="Hello")
|
human_message = HumanMessage(content="Hello")
|
||||||
response = chat([system_message, human_message])
|
response = chat.invoke([system_message, human_message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
|
@ -15,14 +15,6 @@ def friendli_chat() -> ChatFriendli:
|
|||||||
return ChatFriendli(temperature=0, max_tokens=10)
|
return ChatFriendli(temperature=0, max_tokens=10)
|
||||||
|
|
||||||
|
|
||||||
def test_friendli_call(friendli_chat: ChatFriendli) -> None:
|
|
||||||
"""Test call."""
|
|
||||||
message = HumanMessage(content="What is generative AI?")
|
|
||||||
output = friendli_chat([message])
|
|
||||||
assert isinstance(output, AIMessage)
|
|
||||||
assert isinstance(output.content, str)
|
|
||||||
|
|
||||||
|
|
||||||
def test_friendli_invoke(friendli_chat: ChatFriendli) -> None:
|
def test_friendli_invoke(friendli_chat: ChatFriendli) -> None:
|
||||||
"""Test invoke."""
|
"""Test invoke."""
|
||||||
output = friendli_chat.invoke("What is generative AI?")
|
output = friendli_chat.invoke("What is generative AI?")
|
||||||
|
@ -14,7 +14,7 @@ def test_chat_google_palm() -> None:
|
|||||||
"""Test Google PaLM Chat API wrapper."""
|
"""Test Google PaLM Chat API wrapper."""
|
||||||
chat = ChatGooglePalm()
|
chat = ChatGooglePalm()
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ def test_chat_google_palm_system_message() -> None:
|
|||||||
chat = ChatGooglePalm()
|
chat = ChatGooglePalm()
|
||||||
system_message = SystemMessage(content="You are to chat with the user.")
|
system_message = SystemMessage(content="You are to chat with the user.")
|
||||||
human_message = HumanMessage(content="Hello")
|
human_message = HumanMessage(content="Hello")
|
||||||
response = chat([system_message, human_message])
|
response = chat.invoke([system_message, human_message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ def test_gpt_router_call() -> None:
|
|||||||
)
|
)
|
||||||
chat = GPTRouter(models_priority_list=[anthropic_claude])
|
chat = GPTRouter(models_priority_list=[anthropic_claude])
|
||||||
message = HumanMessage(content="Hello World")
|
message = HumanMessage(content="Hello World")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ def test_gpt_router_call_incorrect_model() -> None:
|
|||||||
chat = GPTRouter(models_priority_list=[anthropic_claude])
|
chat = GPTRouter(models_priority_list=[anthropic_claude])
|
||||||
message = HumanMessage(content="Hello World")
|
message = HumanMessage(content="Hello World")
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
chat([message])
|
chat.invoke([message])
|
||||||
|
|
||||||
|
|
||||||
def test_gpt_router_generate() -> None:
|
def test_gpt_router_generate() -> None:
|
||||||
@ -85,7 +85,7 @@ def test_gpt_router_streaming() -> None:
|
|||||||
)
|
)
|
||||||
chat = GPTRouter(models_priority_list=[anthropic_claude], streaming=True)
|
chat = GPTRouter(models_priority_list=[anthropic_claude], streaming=True)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -104,5 +104,5 @@ def test_gpt_router_streaming_callback() -> None:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Write me a 5 line poem.")
|
message = HumanMessage(content="Write me a 5 line poem.")
|
||||||
chat([message])
|
chat.invoke([message])
|
||||||
assert callback_handler.llm_streams > 1
|
assert callback_handler.llm_streams > 1
|
||||||
|
@ -6,7 +6,7 @@ from langchain_community.chat_models.hunyuan import ChatHunyuan
|
|||||||
def test_chat_hunyuan() -> None:
|
def test_chat_hunyuan() -> None:
|
||||||
chat = ChatHunyuan()
|
chat = ChatHunyuan()
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ def test_chat_hunyuan() -> None:
|
|||||||
def test_chat_hunyuan_with_temperature() -> None:
|
def test_chat_hunyuan_with_temperature() -> None:
|
||||||
chat = ChatHunyuan(temperature=0.6)
|
chat = ChatHunyuan(temperature=0.6)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ def test_jinachat() -> None:
|
|||||||
"""Test JinaChat wrapper."""
|
"""Test JinaChat wrapper."""
|
||||||
chat = JinaChat(max_tokens=10)
|
chat = JinaChat(max_tokens=10)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ def test_jinachat_system_message() -> None:
|
|||||||
chat = JinaChat(max_tokens=10)
|
chat = JinaChat(max_tokens=10)
|
||||||
system_message = SystemMessage(content="You are to chat with the user.")
|
system_message = SystemMessage(content="You are to chat with the user.")
|
||||||
human_message = HumanMessage(content="Hello")
|
human_message = HumanMessage(content="Hello")
|
||||||
response = chat([system_message, human_message])
|
response = chat.invoke([system_message, human_message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ def test_jinachat_streaming() -> None:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert callback_handler.llm_streams > 0
|
assert callback_handler.llm_streams > 0
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ def test_konko_chat_test() -> None:
|
|||||||
"""Evaluate basic ChatKonko functionality."""
|
"""Evaluate basic ChatKonko functionality."""
|
||||||
chat_instance = ChatKonko(max_tokens=10)
|
chat_instance = ChatKonko(max_tokens=10)
|
||||||
msg = HumanMessage(content="Hi")
|
msg = HumanMessage(content="Hi")
|
||||||
chat_response = chat_instance([msg])
|
chat_response = chat_instance.invoke([msg])
|
||||||
assert isinstance(chat_response, BaseMessage)
|
assert isinstance(chat_response, BaseMessage)
|
||||||
assert isinstance(chat_response.content, str)
|
assert isinstance(chat_response.content, str)
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ def test_konko_chat_test_openai() -> None:
|
|||||||
"""Evaluate basic ChatKonko functionality."""
|
"""Evaluate basic ChatKonko functionality."""
|
||||||
chat_instance = ChatKonko(max_tokens=10, model="meta-llama/llama-2-70b-chat")
|
chat_instance = ChatKonko(max_tokens=10, model="meta-llama/llama-2-70b-chat")
|
||||||
msg = HumanMessage(content="Hi")
|
msg = HumanMessage(content="Hi")
|
||||||
chat_response = chat_instance([msg])
|
chat_response = chat_instance.invoke([msg])
|
||||||
assert isinstance(chat_response, BaseMessage)
|
assert isinstance(chat_response, BaseMessage)
|
||||||
assert isinstance(chat_response.content, str)
|
assert isinstance(chat_response.content, str)
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ def test_konko_system_msg_test() -> None:
|
|||||||
chat_instance = ChatKonko(max_tokens=10)
|
chat_instance = ChatKonko(max_tokens=10)
|
||||||
sys_msg = SystemMessage(content="Initiate user chat.")
|
sys_msg = SystemMessage(content="Initiate user chat.")
|
||||||
user_msg = HumanMessage(content="Hi there")
|
user_msg = HumanMessage(content="Hi there")
|
||||||
chat_response = chat_instance([sys_msg, user_msg])
|
chat_response = chat_instance.invoke([sys_msg, user_msg])
|
||||||
assert isinstance(chat_response, BaseMessage)
|
assert isinstance(chat_response, BaseMessage)
|
||||||
assert isinstance(chat_response.content, str)
|
assert isinstance(chat_response.content, str)
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ def test_konko_streaming_callback_test() -> None:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
msg = HumanMessage(content="Hi")
|
msg = HumanMessage(content="Hi")
|
||||||
chat_response = chat_instance([msg])
|
chat_response = chat_instance.invoke([msg])
|
||||||
assert callback_instance.llm_streams > 0
|
assert callback_instance.llm_streams > 0
|
||||||
assert isinstance(chat_response, BaseMessage)
|
assert isinstance(chat_response, BaseMessage)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ def test_litellm_call() -> None:
|
|||||||
model="test",
|
model="test",
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ def test_litellm_streaming() -> None:
|
|||||||
"""Test streaming tokens from anthropic."""
|
"""Test streaming tokens from anthropic."""
|
||||||
chat = ChatLiteLLM(model="test", streaming=True)
|
chat = ChatLiteLLM(model="test", streaming=True)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -58,5 +58,5 @@ def test_litellm_streaming_callback() -> None:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Write me a sentence with 10 words.")
|
message = HumanMessage(content="Write me a sentence with 10 words.")
|
||||||
chat([message])
|
chat.invoke([message])
|
||||||
assert callback_handler.llm_streams > 1
|
assert callback_handler.llm_streams > 1
|
||||||
|
@ -184,7 +184,7 @@ def test_litellm_router_call(
|
|||||||
chat = ChatLiteLLMRouter(router=litellm_router)
|
chat = ChatLiteLLMRouter(router=litellm_router)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
|
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
|
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
@ -232,7 +232,7 @@ def test_litellm_router_streaming(
|
|||||||
chat = ChatLiteLLMRouter(router=litellm_router, streaming=True)
|
chat = ChatLiteLLMRouter(router=litellm_router, streaming=True)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
|
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
|
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
@ -255,7 +255,7 @@ def test_litellm_router_streaming_callback(
|
|||||||
)
|
)
|
||||||
message = HumanMessage(content="Write me a sentence with 10 words.")
|
message = HumanMessage(content="Write me a sentence with 10 words.")
|
||||||
|
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
|
|
||||||
assert callback_handler.llm_streams > 1
|
assert callback_handler.llm_streams > 1
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
|
@ -20,7 +20,7 @@ def test_chat_wasm_service() -> None:
|
|||||||
messages = [system_message, user_message]
|
messages = [system_message, user_message]
|
||||||
|
|
||||||
# chat with wasm-chat service
|
# chat with wasm-chat service
|
||||||
response = chat(messages)
|
response = chat.invoke(messages)
|
||||||
|
|
||||||
# check response
|
# check response
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
|
@ -6,6 +6,6 @@ from langchain_community.chat_models.octoai import ChatOctoAI
|
|||||||
def test_chat_octoai() -> None:
|
def test_chat_octoai() -> None:
|
||||||
chat = ChatOctoAI()
|
chat = ChatOctoAI()
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
@ -33,7 +33,7 @@ def test_chat_openai() -> None:
|
|||||||
default_query=None,
|
default_query=None,
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ def test_chat_openai_system_message() -> None:
|
|||||||
chat = ChatOpenAI(max_tokens=10)
|
chat = ChatOpenAI(max_tokens=10)
|
||||||
system_message = SystemMessage(content="You are to chat with the user.")
|
system_message = SystemMessage(content="You are to chat with the user.")
|
||||||
human_message = HumanMessage(content="Hello")
|
human_message = HumanMessage(content="Hello")
|
||||||
response = chat([system_message, human_message])
|
response = chat.invoke([system_message, human_message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ def test_chat_openai_streaming() -> None:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert callback_handler.llm_streams > 0
|
assert callback_handler.llm_streams > 0
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ def test_pai_eas_call() -> None:
|
|||||||
eas_service_url=os.getenv("EAS_SERVICE_URL"),
|
eas_service_url=os.getenv("EAS_SERVICE_URL"),
|
||||||
eas_service_token=os.getenv("EAS_SERVICE_TOKEN"),
|
eas_service_token=os.getenv("EAS_SERVICE_TOKEN"),
|
||||||
)
|
)
|
||||||
response = chat(messages=[HumanMessage(content="Say foo:")])
|
response = chat.invoke([HumanMessage(content="Say foo:")])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -26,8 +26,8 @@ def test_multiple_history() -> None:
|
|||||||
eas_service_token=os.getenv("EAS_SERVICE_TOKEN"),
|
eas_service_token=os.getenv("EAS_SERVICE_TOKEN"),
|
||||||
)
|
)
|
||||||
|
|
||||||
response = chat(
|
response = chat.invoke(
|
||||||
messages=[
|
[
|
||||||
HumanMessage(content="Hello."),
|
HumanMessage(content="Hello."),
|
||||||
AIMessage(content="Hello!"),
|
AIMessage(content="Hello!"),
|
||||||
HumanMessage(content="How are you doing?"),
|
HumanMessage(content="How are you doing?"),
|
||||||
@ -46,14 +46,14 @@ def test_stream() -> None:
|
|||||||
)
|
)
|
||||||
callback_handler = FakeCallbackHandler()
|
callback_handler = FakeCallbackHandler()
|
||||||
callback_manager = CallbackManager([callback_handler])
|
callback_manager = CallbackManager([callback_handler])
|
||||||
response = chat(
|
response = chat.invoke(
|
||||||
messages=[
|
[
|
||||||
HumanMessage(content="Hello."),
|
HumanMessage(content="Hello."),
|
||||||
AIMessage(content="Hello!"),
|
AIMessage(content="Hello!"),
|
||||||
HumanMessage(content="Who are you?"),
|
HumanMessage(content="Who are you?"),
|
||||||
],
|
],
|
||||||
stream=True,
|
stream=True,
|
||||||
callbacks=callback_manager,
|
config={"callbacks": callback_manager},
|
||||||
)
|
)
|
||||||
assert callback_handler.llm_streams > 0
|
assert callback_handler.llm_streams > 0
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
@ -21,7 +21,7 @@ def test_chat_premai() -> None:
|
|||||||
"""Test ChatPremAI wrapper."""
|
"""Test ChatPremAI wrapper."""
|
||||||
chat = ChatPremAI(project_id=8)
|
chat = ChatPremAI(project_id=8)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ def test_chat_prem_system_message() -> None:
|
|||||||
chat = ChatPremAI(project_id=8)
|
chat = ChatPremAI(project_id=8)
|
||||||
system_message = SystemMessage(content="You are to chat with the user.")
|
system_message = SystemMessage(content="You are to chat with the user.")
|
||||||
human_message = HumanMessage(content="Hello")
|
human_message = HumanMessage(content="Hello")
|
||||||
response = chat([system_message, human_message])
|
response = chat.invoke([system_message, human_message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ def test_promptlayer_chat_openai() -> None:
|
|||||||
"""Test PromptLayerChatOpenAI wrapper."""
|
"""Test PromptLayerChatOpenAI wrapper."""
|
||||||
chat = PromptLayerChatOpenAI(max_tokens=10)
|
chat = PromptLayerChatOpenAI(max_tokens=10)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ def test_promptlayer_chat_openai_system_message() -> None:
|
|||||||
chat = PromptLayerChatOpenAI(max_tokens=10)
|
chat = PromptLayerChatOpenAI(max_tokens=10)
|
||||||
system_message = SystemMessage(content="You are to chat with the user.")
|
system_message = SystemMessage(content="You are to chat with the user.")
|
||||||
human_message = HumanMessage(content="Hello")
|
human_message = HumanMessage(content="Hello")
|
||||||
response = chat([system_message, human_message])
|
response = chat.invoke([system_message, human_message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ def test_promptlayer_chat_openai_streaming() -> None:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert callback_handler.llm_streams > 0
|
assert callback_handler.llm_streams > 0
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
|
|
||||||
|
@ -98,9 +98,9 @@ def test_initialization() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_default_call() -> None:
|
def test_default_call() -> None:
|
||||||
"""Test default model(`ERNIE-Bot`) call."""
|
"""Test default model.invoke(`ERNIE-Bot`) call."""
|
||||||
chat = QianfanChatEndpoint()
|
chat = QianfanChatEndpoint()
|
||||||
response = chat(messages=[HumanMessage(content="Hello")])
|
response = chat.invoke([HumanMessage(content="Hello")])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ def test_default_call() -> None:
|
|||||||
def test_model() -> None:
|
def test_model() -> None:
|
||||||
"""Test model kwarg works."""
|
"""Test model kwarg works."""
|
||||||
chat = QianfanChatEndpoint(model="BLOOMZ-7B")
|
chat = QianfanChatEndpoint(model="BLOOMZ-7B")
|
||||||
response = chat(messages=[HumanMessage(content="Hello")])
|
response = chat.invoke([HumanMessage(content="Hello")])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ def test_model() -> None:
|
|||||||
def test_model_param() -> None:
|
def test_model_param() -> None:
|
||||||
"""Test model params works."""
|
"""Test model params works."""
|
||||||
chat = QianfanChatEndpoint()
|
chat = QianfanChatEndpoint()
|
||||||
response = chat(model="BLOOMZ-7B", messages=[HumanMessage(content="Hello")])
|
response = chat.invoke([HumanMessage(content="Hello")], model="BLOOMZ-7B")
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ def test_model_param() -> None:
|
|||||||
def test_endpoint() -> None:
|
def test_endpoint() -> None:
|
||||||
"""Test user custom model deployments like some open source models."""
|
"""Test user custom model deployments like some open source models."""
|
||||||
chat = QianfanChatEndpoint(endpoint="qianfan_bloomz_7b_compressed")
|
chat = QianfanChatEndpoint(endpoint="qianfan_bloomz_7b_compressed")
|
||||||
response = chat(messages=[HumanMessage(content="Hello")])
|
response = chat.invoke([HumanMessage(content="Hello")])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -132,10 +132,8 @@ def test_endpoint() -> None:
|
|||||||
def test_endpoint_param() -> None:
|
def test_endpoint_param() -> None:
|
||||||
"""Test user custom model deployments like some open source models."""
|
"""Test user custom model deployments like some open source models."""
|
||||||
chat = QianfanChatEndpoint()
|
chat = QianfanChatEndpoint()
|
||||||
response = chat(
|
response = chat.invoke(
|
||||||
messages=[
|
[HumanMessage(endpoint="qianfan_bloomz_7b_compressed", content="Hello")]
|
||||||
HumanMessage(endpoint="qianfan_bloomz_7b_compressed", content="Hello")
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
@ -145,8 +143,8 @@ def test_multiple_history() -> None:
|
|||||||
"""Tests multiple history works."""
|
"""Tests multiple history works."""
|
||||||
chat = QianfanChatEndpoint()
|
chat = QianfanChatEndpoint()
|
||||||
|
|
||||||
response = chat(
|
response = chat.invoke(
|
||||||
messages=[
|
[
|
||||||
HumanMessage(content="Hello."),
|
HumanMessage(content="Hello."),
|
||||||
AIMessage(content="Hello!"),
|
AIMessage(content="Hello!"),
|
||||||
HumanMessage(content="How are you doing?"),
|
HumanMessage(content="How are you doing?"),
|
||||||
@ -180,14 +178,14 @@ def test_stream() -> None:
|
|||||||
chat = QianfanChatEndpoint(streaming=True)
|
chat = QianfanChatEndpoint(streaming=True)
|
||||||
callback_handler = FakeCallbackHandler()
|
callback_handler = FakeCallbackHandler()
|
||||||
callback_manager = CallbackManager([callback_handler])
|
callback_manager = CallbackManager([callback_handler])
|
||||||
response = chat(
|
response = chat.invoke(
|
||||||
messages=[
|
[
|
||||||
HumanMessage(content="Hello."),
|
HumanMessage(content="Hello."),
|
||||||
AIMessage(content="Hello!"),
|
AIMessage(content="Hello!"),
|
||||||
HumanMessage(content="Who are you?"),
|
HumanMessage(content="Who are you?"),
|
||||||
],
|
],
|
||||||
stream=True,
|
stream=True,
|
||||||
callbacks=callback_manager,
|
config={"callbacks": callback_manager},
|
||||||
)
|
)
|
||||||
assert callback_handler.llm_streams > 0
|
assert callback_handler.llm_streams > 0
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
@ -15,7 +15,7 @@ def test_initialization() -> None:
|
|||||||
def test_chat_spark_llm() -> None:
|
def test_chat_spark_llm() -> None:
|
||||||
chat = ChatSparkLLM()
|
chat = ChatSparkLLM()
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ def test_chat_spark_llm_streaming() -> None:
|
|||||||
def test_chat_spark_llm_with_domain() -> None:
|
def test_chat_spark_llm_with_domain() -> None:
|
||||||
chat = ChatSparkLLM(spark_llm_domain="generalv3")
|
chat = ChatSparkLLM(spark_llm_domain="generalv3")
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
print(response) # noqa: T201
|
print(response) # noqa: T201
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
@ -39,7 +39,7 @@ def test_chat_spark_llm_with_domain() -> None:
|
|||||||
def test_chat_spark_llm_with_temperature() -> None:
|
def test_chat_spark_llm_with_temperature() -> None:
|
||||||
chat = ChatSparkLLM(temperature=0.9, top_k=2)
|
chat = ChatSparkLLM(temperature=0.9, top_k=2)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat.invoke([message])
|
||||||
print(response) # noqa: T201
|
print(response) # noqa: T201
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
@ -61,7 +61,7 @@ def test_api_key_masked_when_passed_via_constructor(
|
|||||||
def test_default_call() -> None:
|
def test_default_call() -> None:
|
||||||
"""Test default model call."""
|
"""Test default model call."""
|
||||||
chat = ChatTongyi()
|
chat = ChatTongyi()
|
||||||
response = chat(messages=[HumanMessage(content="Hello")])
|
response = chat.invoke([HumanMessage(content="Hello")])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ def test_default_call() -> None:
|
|||||||
def test_model() -> None:
|
def test_model() -> None:
|
||||||
"""Test model kwarg works."""
|
"""Test model kwarg works."""
|
||||||
chat = ChatTongyi(model="qwen-plus")
|
chat = ChatTongyi(model="qwen-plus")
|
||||||
response = chat(messages=[HumanMessage(content="Hello")])
|
response = chat.invoke([HumanMessage(content="Hello")])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -95,8 +95,8 @@ def test_multiple_history() -> None:
|
|||||||
"""Tests multiple history works."""
|
"""Tests multiple history works."""
|
||||||
chat = ChatTongyi()
|
chat = ChatTongyi()
|
||||||
|
|
||||||
response = chat(
|
response = chat.invoke(
|
||||||
messages=[
|
[
|
||||||
HumanMessage(content="Hello."),
|
HumanMessage(content="Hello."),
|
||||||
AIMessage(content="Hello!"),
|
AIMessage(content="Hello!"),
|
||||||
HumanMessage(content="How are you doing?"),
|
HumanMessage(content="How are you doing?"),
|
||||||
@ -111,14 +111,14 @@ def test_stream() -> None:
|
|||||||
chat = ChatTongyi(streaming=True)
|
chat = ChatTongyi(streaming=True)
|
||||||
callback_handler = FakeCallbackHandler()
|
callback_handler = FakeCallbackHandler()
|
||||||
callback_manager = CallbackManager([callback_handler])
|
callback_manager = CallbackManager([callback_handler])
|
||||||
response = chat(
|
response = chat.invoke(
|
||||||
messages=[
|
[
|
||||||
HumanMessage(content="Hello."),
|
HumanMessage(content="Hello."),
|
||||||
AIMessage(content="Hello!"),
|
AIMessage(content="Hello!"),
|
||||||
HumanMessage(content="Who are you?"),
|
HumanMessage(content="Who are you?"),
|
||||||
],
|
],
|
||||||
stream=True,
|
stream=True,
|
||||||
callbacks=callback_manager,
|
config={"callbacks": callback_manager},
|
||||||
)
|
)
|
||||||
assert callback_handler.llm_streams > 0
|
assert callback_handler.llm_streams > 0
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
@ -50,7 +50,7 @@ def test_vertexai_single_call(model_name: str) -> None:
|
|||||||
else:
|
else:
|
||||||
model = ChatVertexAI()
|
model = ChatVertexAI()
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = model([message])
|
response = model.invoke([message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ def test_vertexai_single_call_with_context() -> None:
|
|||||||
)
|
)
|
||||||
context = SystemMessage(content=raw_context)
|
context = SystemMessage(content=raw_context)
|
||||||
message = HumanMessage(content=question)
|
message = HumanMessage(content=question)
|
||||||
response = model([context, message])
|
response = model.invoke([context, message])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ def test_multimodal() -> None:
|
|||||||
"text": "What is shown in this image?",
|
"text": "What is shown in this image?",
|
||||||
}
|
}
|
||||||
message = HumanMessage(content=[text_message, image_message])
|
message = HumanMessage(content=[text_message, image_message])
|
||||||
output = llm([message])
|
output = llm.invoke([message])
|
||||||
assert isinstance(output.content, str)
|
assert isinstance(output.content, str)
|
||||||
|
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ def test_multimodal_history() -> None:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
message3 = HumanMessage(content="What time of day is it?")
|
message3 = HumanMessage(content="What time of day is it?")
|
||||||
response = llm([message1, message2, message3])
|
response = llm.invoke([message1, message2, message3])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ def test_vertexai_single_call_with_examples() -> None:
|
|||||||
output = AIMessage(content=text_answer)
|
output = AIMessage(content=text_answer)
|
||||||
context = SystemMessage(content=raw_context)
|
context = SystemMessage(content=raw_context)
|
||||||
message = HumanMessage(content=question)
|
message = HumanMessage(content=question)
|
||||||
response = model([context, message], examples=[inp, output])
|
response = model.invoke([context, message], examples=[inp, output])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ def test_vertexai_single_call_with_history(model_name: str) -> None:
|
|||||||
message1 = HumanMessage(content=text_question1)
|
message1 = HumanMessage(content=text_question1)
|
||||||
message2 = AIMessage(content=text_answer1)
|
message2 = AIMessage(content=text_answer1)
|
||||||
message3 = HumanMessage(content=text_question2)
|
message3 = HumanMessage(content=text_question2)
|
||||||
response = model([message1, message2, message3])
|
response = model.invoke([message1, message2, message3])
|
||||||
assert isinstance(response, AIMessage)
|
assert isinstance(response, AIMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ def test_parse_chat_history_correct() -> None:
|
|||||||
def test_vertexai_single_call_fails_no_message() -> None:
|
def test_vertexai_single_call_fails_no_message() -> None:
|
||||||
chat = ChatVertexAI()
|
chat = ChatVertexAI()
|
||||||
with pytest.raises(ValueError) as exc_info:
|
with pytest.raises(ValueError) as exc_info:
|
||||||
_ = chat([])
|
_ = chat.invoke([])
|
||||||
assert (
|
assert (
|
||||||
str(exc_info.value)
|
str(exc_info.value)
|
||||||
== "You should provide at least one message to start the chat!"
|
== "You should provide at least one message to start the chat!"
|
||||||
@ -251,9 +251,9 @@ def test_vertexai_args_passed(stop: Optional[str]) -> None:
|
|||||||
model = ChatVertexAI(**prompt_params)
|
model = ChatVertexAI(**prompt_params)
|
||||||
message = HumanMessage(content=user_prompt)
|
message = HumanMessage(content=user_prompt)
|
||||||
if stop:
|
if stop:
|
||||||
response = model([message], stop=[stop])
|
response = model.invoke([message], stop=[stop])
|
||||||
else:
|
else:
|
||||||
response = model([message])
|
response = model.invoke([message])
|
||||||
|
|
||||||
assert response.content == response_text
|
assert response.content == response_text
|
||||||
mock_send_message.assert_called_once_with(user_prompt, candidate_count=1)
|
mock_send_message.assert_called_once_with(user_prompt, candidate_count=1)
|
||||||
|
@ -11,7 +11,7 @@ from tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler
|
|||||||
def test_default_call() -> None:
|
def test_default_call() -> None:
|
||||||
"""Test valid chat call to volc engine."""
|
"""Test valid chat call to volc engine."""
|
||||||
chat = VolcEngineMaasChat()
|
chat = VolcEngineMaasChat()
|
||||||
response = chat(messages=[HumanMessage(content="Hello")])
|
response = chat.invoke([HumanMessage(content="Hello")])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
|
|
||||||
@ -20,8 +20,8 @@ def test_multiple_history() -> None:
|
|||||||
"""Tests multiple history works."""
|
"""Tests multiple history works."""
|
||||||
chat = VolcEngineMaasChat()
|
chat = VolcEngineMaasChat()
|
||||||
|
|
||||||
response = chat(
|
response = chat.invoke(
|
||||||
messages=[
|
[
|
||||||
HumanMessage(content="Hello"),
|
HumanMessage(content="Hello"),
|
||||||
AIMessage(content="Hello!"),
|
AIMessage(content="Hello!"),
|
||||||
HumanMessage(content="How are you?"),
|
HumanMessage(content="How are you?"),
|
||||||
@ -36,14 +36,14 @@ def test_stream() -> None:
|
|||||||
chat = VolcEngineMaasChat(streaming=True)
|
chat = VolcEngineMaasChat(streaming=True)
|
||||||
callback_handler = FakeCallbackHandler()
|
callback_handler = FakeCallbackHandler()
|
||||||
callback_manager = CallbackManager([callback_handler])
|
callback_manager = CallbackManager([callback_handler])
|
||||||
response = chat(
|
response = chat.invoke(
|
||||||
messages=[
|
[
|
||||||
HumanMessage(content="Hello"),
|
HumanMessage(content="Hello"),
|
||||||
AIMessage(content="Hello!"),
|
AIMessage(content="Hello!"),
|
||||||
HumanMessage(content="How are you?"),
|
HumanMessage(content="How are you?"),
|
||||||
],
|
],
|
||||||
stream=True,
|
stream=True,
|
||||||
callbacks=callback_manager,
|
config={"callbacks": callback_manager},
|
||||||
)
|
)
|
||||||
assert callback_handler.llm_streams > 0
|
assert callback_handler.llm_streams > 0
|
||||||
assert isinstance(response.content, str)
|
assert isinstance(response.content, str)
|
||||||
@ -56,14 +56,14 @@ def test_stop() -> None:
|
|||||||
)
|
)
|
||||||
callback_handler = FakeCallbackHandler()
|
callback_handler = FakeCallbackHandler()
|
||||||
callback_manager = CallbackManager([callback_handler])
|
callback_manager = CallbackManager([callback_handler])
|
||||||
response = chat(
|
response = chat.invoke(
|
||||||
messages=[
|
[
|
||||||
HumanMessage(content="repeat: hello world"),
|
HumanMessage(content="repeat: hello world"),
|
||||||
AIMessage(content="hello world"),
|
AIMessage(content="hello world"),
|
||||||
HumanMessage(content="repeat: hello world"),
|
HumanMessage(content="repeat: hello world"),
|
||||||
],
|
],
|
||||||
stream=True,
|
stream=True,
|
||||||
callbacks=callback_manager,
|
config={"callbacks": callback_manager},
|
||||||
stop=["world"],
|
stop=["world"],
|
||||||
)
|
)
|
||||||
assert callback_handler.llm_streams > 0
|
assert callback_handler.llm_streams > 0
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user