Update embeddings and conversation chains
This commit is contained in:
parent
454e80f6d8
commit
291e5f42c0
5 changed files with 24 additions and 29 deletions
|
|
@ -2,19 +2,20 @@ 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."
|
||||||
documentation: str = "https://python.langchain.com/docs/integrations/text_embedding/azureopenai"
|
documentation: str = "https://python.langchain.com/docs/integrations/text_embedding/azureopenai"
|
||||||
beta = False
|
beta = False
|
||||||
|
|
||||||
API_VERSION_OPTIONS = [
|
API_VERSION_OPTIONS = [
|
||||||
"2022-12-01",
|
"2022-12-01",
|
||||||
"2023-03-15-preview",
|
"2023-03-15-preview",
|
||||||
"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,13 +52,13 @@ 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:
|
||||||
raise ValueError("Could not connect to AzureOpenAIEmbeddings API.") from e
|
raise ValueError("Could not connect to AzureOpenAIEmbeddings API.") from e
|
||||||
|
|
||||||
return embeddings
|
return embeddings
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -23,7 +24,7 @@ class OllamaEmbeddingsComponent(CustomComponent):
|
||||||
"temperature": {"display_name": "Model Temperature"},
|
"temperature": {"display_name": "Model Temperature"},
|
||||||
"code": {"show": False},
|
"code": {"show": False},
|
||||||
}
|
}
|
||||||
|
|
||||||
def build(
|
def build(
|
||||||
self,
|
self,
|
||||||
model: str = "llama2",
|
model: str = "llama2",
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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}
|
||||||
|
|
|
||||||
|
|
@ -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";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue