Update embeddings and conversation chains

This commit is contained in:
anovazzi1 2024-01-18 13:38:23 -03:00
commit 291e5f42c0
5 changed files with 24 additions and 29 deletions

View file

@ -2,6 +2,7 @@ from langflow import CustomComponent
from langchain.embeddings.base import Embeddings from langchain.embeddings.base import Embeddings
from langchain_community.embeddings import AzureOpenAIEmbeddings from langchain_community.embeddings import AzureOpenAIEmbeddings
class AzureOpenAIEmbeddingsComponent(CustomComponent): class AzureOpenAIEmbeddingsComponent(CustomComponent):
display_name: str = "AzureOpenAIEmbeddings" display_name: str = "AzureOpenAIEmbeddings"
description: str = "Embeddings model from Azure OpenAI." description: str = "Embeddings model from Azure OpenAI."
@ -14,7 +15,7 @@ class AzureOpenAIEmbeddingsComponent(CustomComponent):
"2023-05-15", "2023-05-15",
"2023-06-01-preview", "2023-06-01-preview",
"2023-07-01-preview", "2023-07-01-preview",
"2023-08-01-preview" "2023-08-01-preview",
] ]
def build_config(self): def build_config(self):
@ -39,10 +40,9 @@ class AzureOpenAIEmbeddingsComponent(CustomComponent):
"required": True, "required": True,
"password": True, "password": True,
}, },
"code": { "code": {"show": False},
"show": False
},
} }
def build( def build(
self, self,
azure_endpoint: str, azure_endpoint: str,
@ -52,10 +52,10 @@ class AzureOpenAIEmbeddingsComponent(CustomComponent):
) -> Embeddings: ) -> Embeddings:
try: try:
embeddings = AzureOpenAIEmbeddings( embeddings = AzureOpenAIEmbeddings(
azure_endpoint = azure_endpoint, azure_endpoint=azure_endpoint,
deployment = azure_deployment, deployment=azure_deployment,
openai_api_version = api_version, openai_api_version=api_version,
openai_api_key = api_key, openai_api_key=api_key,
) )
except Exception as e: except Exception as e:

View file

@ -4,6 +4,7 @@ from langflow import CustomComponent
from langchain.embeddings.base import Embeddings from langchain.embeddings.base import Embeddings
from langchain_community.embeddings import OllamaEmbeddings from langchain_community.embeddings import OllamaEmbeddings
class OllamaEmbeddingsComponent(CustomComponent): class OllamaEmbeddingsComponent(CustomComponent):
""" """
A custom component for implementing an Embeddings Model using Ollama. A custom component for implementing an Embeddings Model using Ollama.
@ -31,11 +32,7 @@ class OllamaEmbeddingsComponent(CustomComponent):
temperature: Optional[float] = None, temperature: Optional[float] = None,
) -> Embeddings: ) -> Embeddings:
try: try:
output = OllamaEmbeddings( output = OllamaEmbeddings(model=model, base_url=base_url, temperature=temperature) # type: ignore
model=model,
base_url=base_url,
temperature=temperature
) # type: ignore
except Exception as e: except Exception as e:
raise ValueError("Could not connect to Ollama API.") from e raise ValueError("Could not connect to Ollama API.") from e
return output return output

View file

@ -25,7 +25,7 @@ class AzureChatOpenAIComponent(CustomComponent):
"2023-06-01-preview", "2023-06-01-preview",
"2023-07-01-preview", "2023-07-01-preview",
"2023-08-01-preview", "2023-08-01-preview",
"2023-12-01-preview" "2023-12-01-preview",
] ]
def build_config(self): def build_config(self):
@ -52,11 +52,7 @@ class AzureChatOpenAIComponent(CustomComponent):
"required": True, "required": True,
"advanced": True, "advanced": True,
}, },
"api_key": { "api_key": {"display_name": "API Key", "required": True, "password": True},
"display_name": "API Key",
"required": True,
"password": True
},
"temperature": { "temperature": {
"display_name": "Temperature", "display_name": "Temperature",
"value": 0.7, "value": 0.7,
@ -71,10 +67,9 @@ class AzureChatOpenAIComponent(CustomComponent):
"advanced": True, "advanced": True,
"info": "Maximum number of tokens to generate.", "info": "Maximum number of tokens to generate.",
}, },
"code": { "code": {"show": False},
"show": False
},
} }
def build( def build(
self, self,
model: str, model: str,

View file

@ -67,7 +67,9 @@ Human: {input}
class MidJourneyPromptChain(BaseCustomConversationChain): class MidJourneyPromptChain(BaseCustomConversationChain):
"""MidJourneyPromptChain is a chain you can use to generate new MidJourney prompts.""" """MidJourneyPromptChain is a chain you can use to generate new MidJourney prompts."""
template: Optional[str] = """I want you to act as a prompt generator for Midjourney's artificial intelligence program. template: Optional[
str
] = """I want you to act as a prompt generator for Midjourney's artificial intelligence program.
Your job is to provide detailed and creative descriptions that will inspire unique and interesting images from the AI. Your job is to provide detailed and creative descriptions that will inspire unique and interesting images from the AI.
Keep in mind that the AI is capable of understanding a wide range of language and can interpret abstract concepts, so feel free to be as imaginative and descriptive as possible. Keep in mind that the AI is capable of understanding a wide range of language and can interpret abstract concepts, so feel free to be as imaginative and descriptive as possible.
For example, you could describe a scene from a futuristic city, or a surreal landscape filled with strange creatures. For example, you could describe a scene from a futuristic city, or a surreal landscape filled with strange creatures.
@ -81,7 +83,9 @@ class MidJourneyPromptChain(BaseCustomConversationChain):
class TimeTravelGuideChain(BaseCustomConversationChain): class TimeTravelGuideChain(BaseCustomConversationChain):
template: Optional[str] = """I want you to act as my time travel guide. You are helpful and creative. I will provide you with the historical period or future time I want to visit and you will suggest the best events, sights, or people to experience. Provide the suggestions and any necessary information. template: Optional[
str
] = """I want you to act as my time travel guide. You are helpful and creative. I will provide you with the historical period or future time I want to visit and you will suggest the best events, sights, or people to experience. Provide the suggestions and any necessary information.
Current conversation: Current conversation:
{history} {history}
Human: {input} Human: {input}

View file

@ -5,7 +5,6 @@ import BuildTrigger from "./buildTrigger";
import ChatTrigger from "./chatTrigger"; import ChatTrigger from "./chatTrigger";
import * as _ from "lodash"; import * as _ from "lodash";
import { getBuildStatus } from "../../controllers/API";
import FormModal from "../../modals/formModal"; import FormModal from "../../modals/formModal";
import useFlowStore from "../../stores/flowStore"; import useFlowStore from "../../stores/flowStore";
import { NodeType } from "../../types/flow"; import { NodeType } from "../../types/flow";