Skip to content

Commit

Permalink
Merge pull request #156 from deepset-ai/chatmessage-use-text
Browse files Browse the repository at this point in the history
`ChatMessage` - access `text` instead of `content`
  • Loading branch information
anakin87 authored Dec 12, 2024
2 parents 1ea2fd2 + 329f644 commit c4d34b3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions notebooks/charactercodex_llamafile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
"\n",
"for hint_number in range(1, MAX_HINTS + 1):\n",
" res = hint_generation_pipeline.run({\"character\": random_character, \"previous_hints\": previous_hints})\n",
" hint = res[\"generator\"][\"replies\"][0].content\n",
" hint = res[\"generator\"][\"replies\"][0].text\n",
"\n",
" previous_hints.append(hint)\n",
" print(f\"✨ Hint {hint_number}: {hint}\")\n",
Expand Down Expand Up @@ -692,9 +692,9 @@
" inverted_messages = []\n",
" for message in messages:\n",
" if message.is_from(ChatRole.USER):\n",
" inverted_messages.append(ChatMessage.from_assistant(message.content))\n",
" inverted_messages.append(ChatMessage.from_assistant(message.text))\n",
" elif message.is_from(ChatRole.ASSISTANT):\n",
" inverted_messages.append(ChatMessage.from_user(message.content))\n",
" inverted_messages.append(ChatMessage.from_user(message.text))\n",
" else:\n",
" inverted_messages.append(message)\n",
" return inverted_messages"
Expand Down Expand Up @@ -1338,21 +1338,21 @@
"second_character_messages = [system_message]\n",
"\n",
"turn = 1\n",
"print(f\"{first_name} 🕺: {start_message.content}\")\n",
"print(f\"{first_name} 🕺: {start_message.text}\")\n",
"\n",
"while turn < MAX_TURNS:\n",
" second_character_messages=invert_roles(first_character_messages)\n",
" new_message = character_pipeline.run({\"template\":second_character_messages, \"template_variables\":{\"character_data\":second_character_data}})[\"generator\"][\"replies\"][0]\n",
" second_character_messages.append(new_message)\n",
" print(f\"\\n\\n{second_name} 🪖: {new_message.content}\")\n",
" print(f\"\\n\\n{second_name} 🪖: {new_message.text}\")\n",
"\n",
" turn += 1\n",
" print(\"-\"*20)\n",
"\n",
" first_character_messages=invert_roles(second_character_messages)\n",
" new_message = character_pipeline.run({\"template\":first_character_messages, \"template_variables\":{\"character_data\":first_character_data}})[\"generator\"][\"replies\"][0]\n",
" first_character_messages.append(new_message)\n",
" print(f\"\\n\\n{first_name} 🕺: {new_message.content}\")\n",
" print(f\"\\n\\n{first_name} 🕺: {new_message.text}\")\n",
"\n",
" turn += 1"
]
Expand Down
6 changes: 3 additions & 3 deletions notebooks/chat_with_SQL_3_ways.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@
"import json\n",
"\n",
"## Parse function calling information\n",
"function_call = json.loads(response[\"replies\"][0].content)[0]\n",
"function_call = json.loads(response[\"replies\"][0].text)[0]\n",
"function_name = function_call[\"function\"][\"name\"]\n",
"function_args = json.loads(function_call[\"function\"][\"arguments\"])\n",
"print(\"Function Name:\", function_name)\n",
Expand Down Expand Up @@ -759,7 +759,7 @@
" while True:\n",
" # if OpenAI response is a tool call\n",
" if response and response[\"replies\"][0].meta[\"finish_reason\"] == \"tool_calls\":\n",
" function_calls = json.loads(response[\"replies\"][0].content)\n",
" function_calls = json.loads(response[\"replies\"][0].text)\n",
" for function_call in function_calls:\n",
" ## Parse function calling information\n",
" function_name = function_call[\"function\"][\"name\"]\n",
Expand All @@ -776,7 +776,7 @@
" else:\n",
" messages.append(response[\"replies\"][0])\n",
" break\n",
" return response[\"replies\"][0].content\n"
" return response[\"replies\"][0].text\n"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions notebooks/conversational_rag_using_memory.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
"\n",
" Conversation history:\n",
" {% for memory in memories %}\n",
" {{ memory.content }}\n",
" {{ memory.text }}\n",
" {% endfor %}\n",
"\n",
" Supporting documents:\n",
Expand Down Expand Up @@ -519,7 +519,7 @@
"\n",
" Conversation history:\n",
" {% for memory in memories %}\n",
" {{ memory.content }}\n",
" {{ memory.text }}\n",
" {% endfor %}\n",
"\n",
" User Query: {{query}}\n",
Expand Down Expand Up @@ -679,7 +679,7 @@
" search_query = res['query_rephrase_llm']['replies'][0]\n",
" print(f\" 🔎 Search Query: {search_query}\")\n",
" assistant_resp = res['llm']['replies'][0]\n",
" print(f\"🤖 {assistant_resp.content}\")"
" print(f\"🤖 {assistant_resp.text}\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/gemma_chat_rag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
" messages.append(ChatMessage.from_user(msg))\n",
" response = generator.run(messages=messages)\n",
" assistant_resp = response['replies'][0]\n",
" print(\"🤖 \"+assistant_resp.content)\n",
" print(\"🤖 \"+assistant_resp.text)\n",
" messages.append(assistant_resp)"
]
},
Expand Down
6 changes: 3 additions & 3 deletions notebooks/prompt_customization_for_Anthropic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@
}
],
"source": [
"print(result[\"llm\"][\"replies\"][0].content)"
"print(result[\"llm\"][\"replies\"][0].text)"
]
},
{
Expand Down Expand Up @@ -882,7 +882,7 @@
"source": [
"import re\n",
"\n",
"re.findall(r'<quote .*?>([\\s\\S]*?)<\\/quote>', result[\"llm\"][\"replies\"][0].content)"
"re.findall(r'<quote .*?>([\\s\\S]*?)<\\/quote>', result[\"llm\"][\"replies\"][0].text)"
]
},
{
Expand Down Expand Up @@ -919,7 +919,7 @@
"source": [
"import re\n",
"\n",
"re.findall(r'<answer>([\\s\\S]*?)<\\/answer>', result[\"llm\"][\"replies\"][0].content)"
"re.findall(r'<answer>([\\s\\S]*?)<\\/answer>', result[\"llm\"][\"replies\"][0].text)"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions notebooks/vertexai-gemini-examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@
"outputs": [],
"source": [
"\n",
"weather = get_current_weather(**res[\"replies\"][0].content)\n",
"weather = get_current_weather(**res[\"replies\"][0].text)\n",
"\n",
"messages += res[\"replies\"] + [ChatMessage.from_function(content=weather, name=\"get_current_weather\")]\n",
"\n",
"res = gemini_chat.run(messages = messages)\n",
"res[\"replies\"][0].content"
"res[\"replies\"][0].text"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/vllm_inference_engine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
" messages.append(ChatMessage.from_user(msg))\n",
" response = generator.run(messages=messages)\n",
" assistant_resp = response['replies'][0]\n",
" print(\"🤖 \"+assistant_resp.content)\n",
" print(\"🤖 \"+assistant_resp.text)\n",
" messages.append(assistant_resp)"
]
}
Expand Down

0 comments on commit c4d34b3

Please sign in to comment.