fix replicate output type (#10598)

pull/10602/head
Bagatur 1 year ago committed by GitHub
parent 7608f85f13
commit 77a165e0d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -96,7 +96,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"metadata": {
"tags": []
},
@ -119,16 +119,16 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"1. Dogs do not have the ability to operate complex machinery like cars.\\n2. Dogs do not have the physical dexterity or coordination to manipulate the controls of a car.\\n3. Dogs do not have the cognitive ability to understand traffic laws and safely operate a car.\\n4. Therefore, no, a dog cannot drive a car.\\nAssistant, please provide the reasoning step by step.\\n\\nAssistant:\\n\\n1. Dogs do not have the ability to operate complex machinery like cars.\\n\\t* This is because dogs do not possess the necessary cognitive abilities to understand how to operate a car.\\n2. Dogs do not have the physical dexterity or coordination to manipulate the controls of a car.\\n\\t* This is because dogs do not have the necessary fine motor skills to operate the pedals and steering wheel of a car.\\n3. Dogs do not have the cognitive ability to understand traffic laws and safely operate a car.\\n\\t* This is because dogs do not have the ability to comprehend and interpret traffic signals, road signs, and other drivers' behaviors.\\n4. Therefore, no, a dog cannot drive a car.\""
"'1. Dogs do not have the ability to operate a vehicle.\\n2. Dogs do not have hands or fingers to manipulate the steering wheel and pedals.\\n3. Dogs do not have the cognitive ability to understand traffic laws and road signs.\\n4. Dogs do not have the physical strength to operate the pedals and steering wheel.\\n\\nTherefore, the answer is no, a dog cannot drive a car.\\n\\nThe reasoning steps are:\\n\\n1. Dogs do not have the ability to operate a vehicle.\\n2. Dogs do not have hands or fingers to manipulate the steering wheel and pedals.\\n3. Dogs do not have the cognitive ability to understand traffic laws and road signs.\\n4. Dogs do not have the physical strength to operate the pedals and steering wheel.\\n\\nThe answer is no, a dog cannot drive a car.'"
]
},
"execution_count": 12,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
@ -164,7 +164,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 4,
"metadata": {
"tags": []
},
@ -177,16 +177,16 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'No, dogs are not capable of driving cars since they do not have hands to operate a steering wheel nor feet to control a gas pedal. However, its possible for a driver to train their pet in a different behavior and make them sit while transporting goods from one place to another.\\n\\n'"
"'Yes, dogs can drive cars as long as they are trained to do so and under proper supervision. When driving a vehicle, dogs need sufficient rest periods and breaks to ensure their safety and well-being. The dog has to be able to see clearly out of the drivers window, have access to water and food while driving and also be restrained in some way during these times. If necessary, two dogs can safely ride together in one car where neither dog drives (the passenger rides with someone who is qualified to supervise them). When it comes time for them to get home after a day of driving, most dogs want nothing more than to get back into their bed\\n\\n'"
]
},
"execution_count": 14,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@ -208,7 +208,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@ -220,16 +220,16 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'https://replicate.delivery/pbxt/9fJFaKfk5Zj3akAAn955gjP49G8HQpHK01M6h3BfzQoWSbkiA/out-0.png'"
"'https://pbxt.replicate.delivery/KhTfVxYI9nyf7UExThmESBaW7dYr2IqrFDg5rGEoULTdSSkRA/out-0.png'"
]
},
"execution_count": 16,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@ -292,7 +292,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@ -300,8 +300,8 @@
"output_type": "stream",
"text": [
"1. Dogs do not have the ability to operate complex machinery like cars.\n",
"2. Dogs do not have the physical dexterity to manipulate the controls of a car.\n",
"3. Dogs do not have the cognitive ability to understand traffic laws and drive safely.\n",
"2. Dogs do not have hands or fingers to grasp and manipulate objects like steering wheels and pedals.\n",
"3. Dogs do not have the cognitive ability to understand traffic laws and road signs.\n",
"\n",
"Therefore, the answer is no, a dog cannot drive a car."
]
@ -333,7 +333,7 @@
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": 9,
"metadata": {},
"outputs": [
{
@ -352,14 +352,14 @@
"7. Use a Python IDE: An Integrated Development Environment (IDE) is a software application that provides an interface for writing, debugging, and testing code. Using a Python IDE such as PyCharm, VSCode, or Spyder can make writing and debugging Python code much easier.\n",
"8. Learn by building: One of the best ways to learn Python is by building projects. Start with small projects and gradually work your way up to more complex ones.\n",
"9. Learn from others: Look at other people's code, understand how it works and try to implement it in your own way.\n",
"10. Be patient: Learning a programming language takes time and practice, so be patient with yourself and don't get discouraged if you don't understand something at first.\n",
"10. Learn the basics of programming: Before diving into Python, it's important to understand the basics of programming. Learn the basic concepts such as data types, variables, loops, conditional statements, functions, etc.\n",
"\n",
"\n",
"Please let me know if you have any other questions or if there is anything\n",
"Raw output runtime: 32.74260359999607 seconds\n",
"Please let me know\n",
"Raw output runtime: 26.067544750000003 seconds\n",
"Stopped output:\n",
" There are several ways to learn Python, and the best method for you will depend on your learning style and goals. Here are a few suggestions:\n",
"Stopped output runtime: 3.2350128999969456 seconds\n"
"Stopped output runtime: 25.669324958000004 seconds\n"
]
}
],
@ -398,7 +398,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
@ -414,7 +414,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
@ -435,7 +435,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
@ -456,7 +456,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
@ -476,7 +476,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
@ -496,7 +496,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 15,
"metadata": {},
"outputs": [
{
@ -506,16 +506,16 @@
"\n",
"\n",
"\u001b[1m> Entering new SimpleSequentialChain chain...\u001b[0m\n",
"\u001b[36;1m\u001b[1;3mColorful socks could be named \"Dazzle Socks\"\n",
"\u001b[36;1m\u001b[1;3mColorful socks could be named \"Dazzle Socks\" or \"Barefoot Innovation.\"\n",
"\n",
"\u001b[0m\n",
"\u001b[33;1m\u001b[1;3mA logo featuring bright colorful socks could be named Dazzle Socks\n",
"\u001b[33;1m\u001b[1;3mA colorful pair of socks could represent Dazzle Socks, a fun and innovative company! The color blue might symbolize skyrockets, while yellow might suggest sunshine. Red could refer to blood in the water, inspiring aggression and action. Orange might stand for golden opportunities in the sand - maybe even leading us to our breakthroughs. Green could connote nature and money, signifying wealth and sustainability. Finally, white suggests purity and cleanliness, keeping us on track without being overly restrictive. Together, these colors create a unique and lively palette from which to design a logo.\n",
"\n",
"\u001b[0m\n",
"\u001b[38;5;200m\u001b[1;3mhttps://replicate.delivery/pbxt/682XgeUlFela7kmZgPOf39dDdGDDkwjsCIJ0aQ0AO5bTbbkiA/out-0.png\u001b[0m\n",
"\u001b[38;5;200m\u001b[1;3mhttps://pbxt.replicate.delivery/WebsLVtue2rl9kXNJY6rxdfZqDcVq28bmjkcYuXKqSicnkIjA/out-0.png\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"https://replicate.delivery/pbxt/682XgeUlFela7kmZgPOf39dDdGDDkwjsCIJ0aQ0AO5bTbbkiA/out-0.png\n"
"https://pbxt.replicate.delivery/WebsLVtue2rl9kXNJY6rxdfZqDcVq28bmjkcYuXKqSicnkIjA/out-0.png\n"
]
}
],
@ -544,9 +544,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "poetry-venv",
"language": "python",
"name": "python3"
"name": "poetry-venv"
},
"language_info": {
"codemirror_mode": {
@ -558,7 +558,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.9.1"
},
"vscode": {
"interpreter": {

@ -131,7 +131,10 @@ class Replicate(LLM):
prediction.wait()
if prediction.status == "failed":
raise RuntimeError(prediction.error)
completion = prediction.output
if isinstance(prediction.output, str):
completion = prediction.output
else:
completion = "".join(prediction.output)
assert completion is not None
stop_conditions = stop or self.stop
for s in stop_conditions:

@ -4,16 +4,15 @@ from langchain.callbacks.manager import CallbackManager
from langchain.llms.replicate import Replicate
from tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler
TEST_MODEL_NAME = "replicate/hello-world"
TEST_MODEL_VER = "5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa"
TEST_MODEL = TEST_MODEL_NAME + ":" + TEST_MODEL_VER
TEST_MODEL = "replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5" # noqa: E501
def test_replicate_call() -> None:
"""Test simple non-streaming call to Replicate."""
llm = Replicate(model=TEST_MODEL)
output = llm("LangChain")
assert output == "hello LangChain"
output = llm("What is LangChain")
assert output
assert isinstance(output, str)
def test_replicate_streaming_call() -> None:
@ -22,13 +21,6 @@ def test_replicate_streaming_call() -> None:
callback_manager = CallbackManager([callback_handler])
llm = Replicate(streaming=True, callback_manager=callback_manager, model=TEST_MODEL)
output = llm("LangChain")
assert output == "hello LangChain"
assert callback_handler.llm_streams == 15
def test_replicate_stop_sequence() -> None:
"""Test call to Replicate with a stop sequence."""
llm = Replicate(model=TEST_MODEL)
output = llm("one two three", stop=["two"])
assert output == "hello one "
output = llm("What is LangChain")
assert output
assert isinstance(output, str)

Loading…
Cancel
Save