Soulter / hugging-chat-api

HuggingChat Python APIπŸ€—
GNU Affero General Public License v3.0
870 stars 125 forks source link

TypeError: unsupported operand type(s) for |: '_GenericAlias' and 'type' #87

Closed IntelligenzaArtificiale closed 1 year ago

IntelligenzaArtificiale commented 1 year ago

Hi guys,

i have this error with new version

class ChatBot:

  File "/home/adminuser/venv/lib/python3.9/site-packages/hugchat/hugchat.py", line 494, in ChatBot

    ) -> typing.Generator[dict, None, None] | dict:

TypeError: unsupported operand type(s) for |: '_GenericAlias' and 'type'
Soulter commented 1 year ago

"|" is not available on python3.9. We'll fix it soon to adapt lower python interpreters, you can degrade to v0.2.7 when we are fixing the problem.

IntelligenzaArtificiale commented 1 year ago

thank you, you are the best πŸ€—

IntelligenzaArtificiale commented 1 year ago

I Love u guys πŸš€

I have some app based on our api πŸ˜…

Could it help you if I develop a custom LLM connector for your API's langchain?

Some time ago with your bee I managed to run AUTOGPT without paying the API.

With this custom langchain LLM wrapper anyone can develop for free app like talk with pdf, python interpreter, etc...

Let me know if you're interested :)

IntelligenzaArtificiale commented 1 year ago

Of course I would develop it for free for you, I respect you very much.

If you want, I am also willing to send you the code without taking credit

Soulter commented 1 year ago

I Love u guys πŸš€

I have some app based on our api πŸ˜…

Could it help you if I develop a custom LLM connector for your API's langchain?

Some time ago with your bee I managed to run AUTOGPT without paying the API.

With this custom langchain LLM wrapper anyone can develop for free app like talk with pdf, python interpreter, etc...

Let me know if you're interested :)

wow that's cool, feel free to develop it!

IntelligenzaArtificiale commented 1 year ago

Hy guys πŸš€, I hope I don't disturb you.

I developed LLM langchain custom wrapper. Now you can use this api with langchain in a similar way to how OpenAI models are used.

Try this example: This example demonstrates how to use HCA to interact with a language model to answer a question based on a context template. Users can modify the query in the prompt_template.format() call to ask different questions and get responses from the language model. This showcases the flexibility of HCA in handling various NLP tasks.

from HCA import HCA
from langchain import PromptTemplate

# Initialize the HCA instance with your HuggingFace credentials
llm = HCA(email="YOUR_EMAIL", password="YOUR_PASSWORD", log=True, model=1)

# Define a template for your prompt
template = """Answer the question based on the context below. If the
question cannot be answered using the information provided, answer
with "I don't know".

Context: Large Language Models (LLMs) are the latest models used in NLP.
Their superior performance over smaller models has made them incredibly
useful for developers building NLP-enabled applications. These models
can be accessed via Hugging Face's `transformers` library, via OpenAI
using the `openai` library, and via Cohere using the `cohere` library.

Question: {query}

Answer: """

# Create a PromptTemplate for generating prompts
prompt_template = PromptTemplate(
    input_variables=["query"],
    template=template
)

# Generate a response to a specific question
response = llm(
    prompt_template.format(
        query="Which libraries and model providers offer LLMs?"
    )
)

print(response)

LINK FOR CUSTOM LLM WRAPPERπŸ€—

IntelligenzaArtificiale commented 1 year ago

Now evryone can create and develop custom langchain agent based on HuggingChat model :)

@Soulter thanks for this opportunity

IntelligenzaArtificiale commented 1 year ago

This is another simple example that shows the potential of the custom langchain connector.

from HCA import HCA

from langchain.agents import initialize_agent, AgentType
from langchain.tools.yahoo_finance_news import YahooFinanceNewsTool

llm = HCA(email="yourEmail", password="YourPSW" , model=0, temperature=0.1)

tools = [YahooFinanceNewsTool()]
agent_chain = initialize_agent(
    tools,
    llm,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
)

agent_chain.run(
    "What happens today with Microsoft stocks?",
)