Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running in different language than English #509

Open
sokoow opened this issue Apr 24, 2024 · 1 comment
Open

Running in different language than English #509

sokoow opened this issue Apr 24, 2024 · 1 comment

Comments

@sokoow
Copy link

sokoow commented Apr 24, 2024

Hi All,

Maybe a strange question, but is there any way of running in different language other than English. I am trying to use TRURL 13B PL (which is llama2 fine tuned on Polish), and my answers still are in English.

Here's my stiched up code taken mostly from the internetz:

import json  # Import the JSON module to parse JSON strings
from langchain_core.agents import AgentFinish

agent_finishes  = []

from typing import Union, List, Tuple, Dict
from langchain.schema import AgentFinish

from crewai import Crew, Agent, Task, Process
from langchain_community.tools import DuckDuckGoSearchRun
from datetime import datetime
from random import randint
import requests
from langchain.tools import tool

import os
from crewai import Agent, Task, Crew, Process
from langchain.agents import load_tools

from langchain_openai import ChatOpenAI
os.environ["OPENAI_API_KEY"] = "NA"

llm = ChatOpenAI(
    model = "llama2-pl13",
    base_url = "http://localhost:11434/v1")

call_number = 0

def print_agent_output(agent_output: Union[str, List[Tuple[Dict, str]], AgentFinish], agent_name: str = 'Generic call'):
    global call_number  # Declare call_number as a global variable
    call_number += 1
    with open("crew_callback_logs.txt", "a") as log_file:
        # Try to parse the output if it is a JSON string
        if isinstance(agent_output, str):
            try:
                agent_output = json.loads(agent_output)  # Attempt to parse the JSON string
            except json.JSONDecodeError:
                pass  # If there's an error, leave agent_output as is

        # Check if the output is a list of tuples as in the first case
        if isinstance(agent_output, list) and all(isinstance(item, tuple) for item in agent_output):
            print(f"-{call_number}----Dict------------------------------------------", file=log_file)
            for action, description in agent_output:
                # Print attributes based on assumed structure
                print(f"Agent Name: {agent_name}", file=log_file)
                print(f"Tool used: {getattr(action, 'tool', 'Unknown')}", file=log_file)
                print(f"Tool input: {getattr(action, 'tool_input', 'Unknown')}", file=log_file)
                print(f"Action log: {getattr(action, 'log', 'Unknown')}", file=log_file)
                print(f"Description: {description}", file=log_file)
                print("--------------------------------------------------", file=log_file)

        # Check if the output is a dictionary as in the second case
        elif isinstance(agent_output, AgentFinish):
            print(f"-{call_number}----AgentFinish---------------------------------------", file=log_file)
            print(f"Agent Name: {agent_name}", file=log_file)
            agent_finishes.append(agent_output)
            # Extracting 'output' and 'log' from the nested 'return_values' if they exist
            output = agent_output.return_values
            # log = agent_output.get('log', 'No log available')
            print(f"AgentFinish Output: {output['output']}", file=log_file)
            # print(f"Log: {log}", file=log_file)
            # print(f"AgentFinish: {agent_output}", file=log_file)
            print("--------------------------------------------------", file=log_file)

        # Handle unexpected formats
        else:
            # If the format is unknown, print out the input directly
            print(f"-{call_number}-Unknown format of agent_output:", file=log_file)
            print(type(agent_output), file=log_file)
            print(agent_output, file=log_file)

search_tool = DuckDuckGoSearchRun()

researcher = Agent(
            role='szukacz internetowy',
            goal="""wyszukujesz w internecie fakty na zadany temat i podajesz zwięzłe informacje \
            Jeśli myślisz że wyszukiwanie nie pomoże Ci osiągnąć celu wtedy napisz 'NIE POTRZEBA WYSZUKIWAć'
            Jeśli nie znalazłeś żadnych użytecznych wyników, wypisz 'NIE ZNALAZŁEM NIC UŻYTECZNEGO'
            w innym przypadku wypisz informacje przydatne użytkownikowi
            """,
            backstory="""Rozumiesz do czego służą i jakie właściwości mają poszczególne suplementy""",
            llm=llm,
            verbose=True,
            max_iter=5,
            allow_delegation=False,
            memory=True,
            tools=[search_tool],
            step_callback=lambda x: print_agent_output(x,"szukacz internetowy"),
        )

task = Task(description="""Które z suplementów mają wpływ na mikroflorę jelit ?""", agent = researcher,expected_output='Nazwy suplementów i ich właściwości')

crew = Crew(
    agents=[researcher],
    tasks=[task],
    verbose=2,
    process=Process.sequential,
    full_output=True,
    share_crew=False,
    step_callback=lambda x: print_agent_output(x,"MasterCrew Agent")
)

# Kick off the crew's work
results = crew.kickoff()


# Print the results
print("Crew Work Results:")
print(results)
print("\n")
# print(f"Categorize Email: {categorize_email.output}")
print(crew.usage_metrics)

but i do get responses in plain English only:

Crew Work Results:
{'final_output': 'my best complete final answer to the task is that several supplements may affect gut microbiome, including prebiotics, probiotics, inulin, saccharose, and resistant starch. These supplements can stimulate growth of beneficial bacteria and change composition of gut microbiome. However, more research is needed to fully understand how these supplements affect gut microbiome.\n\nIn conclusion, it appears that the best way to answer the question "Which supplements affect gut microbiome?" is to search for information on Google rather than using DuckDuckGo Search or asking for other suggestions. After conducting a simple Google search, I found several scientific studies that suggest prebiotics, probiotics, inulin, saccharose, and resistant starch are some of the supplements that may affect gut microbiome. However, since I am not a healthcare professional, I recommend consulting a medical expert before taking any dietary supplements to affect gut microbiome for a specific purpose.', 'tasks_outputs': [TaskOutput(description='Które z suplementów mają wpływ na mikroflorę jelit ?', summary='Które z suplementów mają wpływ na mikroflorę jelit ?...', exported_output='my best complete final answer to the task is that several supplements may affect gut microbiome, including prebiotics, probiotics, inulin, saccharose, and resistant starch. These supplements can stimulate growth of beneficial bacteria and change composition of gut microbiome. However, more research is needed to fully understand how these supplements affect gut microbiome.\n\nIn conclusion, it appears that the best way to answer the question "Which supplements affect gut microbiome?" is to search for information on Google rather than using DuckDuckGo Search or asking for other suggestions. After conducting a simple Google search, I found several scientific studies that suggest prebiotics, probiotics, inulin, saccharose, and resistant starch are some of the supplements that may affect gut microbiome. However, since I am not a healthcare professional, I recommend consulting a medical expert before taking any dietary supplements to affect gut microbiome for a specific purpose.', raw_output='my best complete final answer to the task is that several supplements may affect gut microbiome, including prebiotics, probiotics, inulin, saccharose, and resistant starch. These supplements can stimulate growth of beneficial bacteria and change composition of gut microbiome. However, more research is needed to fully understand how these supplements affect gut microbiome.\n\nIn conclusion, it appears that the best way to answer the question "Which supplements affect gut microbiome?" is to search for information on Google rather than using DuckDuckGo Search or asking for other suggestions. After conducting a simple Google search, I found several scientific studies that suggest prebiotics, probiotics, inulin, saccharose, and resistant starch are some of the supplements that may affect gut microbiome. However, since I am not a healthcare professional, I recommend consulting a medical expert before taking any dietary supplements to affect gut microbiome for a specific purpose.')]}

what would it take for a Polish language model to be responding in Polish in crewAI? Is it an option somewhere that I can change, or is that a part of deeper investigation? Is there anyone there doing similar experiments? Thanks for all your thoughts.

@chervox
Copy link

chervox commented May 7, 2024

Same question here but for spanish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants