From 97b6bbb143a73ecd3697c987dcac52c1213ece21 Mon Sep 17 00:00:00 2001 From: Sai Kolasani Date: Wed, 14 Aug 2024 14:13:32 -0700 Subject: [PATCH 01/10] wip --- .../components/models/PerplexityModel.py | 46 +++++++++++++++++++ .../langflow/components/models/__init__.py | 2 + 2 files changed, 48 insertions(+) create mode 100644 src/backend/base/langflow/components/models/PerplexityModel.py diff --git a/src/backend/base/langflow/components/models/PerplexityModel.py b/src/backend/base/langflow/components/models/PerplexityModel.py new file mode 100644 index 00000000000..501d566af5d --- /dev/null +++ b/src/backend/base/langflow/components/models/PerplexityModel.py @@ -0,0 +1,46 @@ +from langchain_community.chat_models import ChatPerplexity +from pydantic.v1 import SecretStr + +from langflow.base.models.model import LCModelComponent +from langflow.field_typing import LanguageModel +from langflow.io import FloatInput, SecretStrInput, DropdownInput + + +class PerplexityComponent(LCModelComponent): + display_name = "Perplexity" + description = "Generate text using Perplexity LLMs." + documentation = "https://python.langchain.com/docs/modules/model_io/models/llms/integrations/cohere" + icon = "Google" + name = "PerplexityModel" + + inputs = LCModelComponent._base_inputs + [ + DropdownInput( + name="model_name", + display_name="Model Name", + advanced=False, + options=['llama-3-sonar-small-32k-online'], + value="llama-3-sonar-small-32k-online", + ), + SecretStrInput( + name="api_key", + display_name="Perplexity API Key", + info="The Perplexity API Key to use for the Perplexity model.", + advanced=False, + ), + FloatInput(name="temperature", display_name="Temperature", value=0.75), + + ] + + def build_model(self) -> LanguageModel: # type: ignore[type-var] + api_key = SecretStr(self.api_key).get_secret_value() + temperature = self.temperature + model = self.model_name + + + output = ChatPerplexity( + model=model, + temperature=temperature or 0.75, + pplx_api_key=api_key, + ) + + return output # type: ignore diff --git a/src/backend/base/langflow/components/models/__init__.py b/src/backend/base/langflow/components/models/__init__.py index 3e708d5a8de..08385063c66 100644 --- a/src/backend/base/langflow/components/models/__init__.py +++ b/src/backend/base/langflow/components/models/__init__.py @@ -9,6 +9,7 @@ from .OllamaModel import ChatOllamaComponent from .OpenAIModel import OpenAIModelComponent from .VertexAiModel import ChatVertexAIComponent +from .PerplexityModel import PerplexityComponent __all__ = [ "AIMLModelComponent", @@ -22,5 +23,6 @@ "ChatOllamaComponent", "OpenAIModelComponent", "ChatVertexAIComponent", + "PerplexityComponent", "base", ] From ada5d95c9f18504f0c14fa687dd7c6d2bc17629e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 14 Aug 2024 21:21:14 +0000 Subject: [PATCH 02/10] [autofix.ci] apply automated fixes --- .../base/langflow/components/models/PerplexityModel.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/backend/base/langflow/components/models/PerplexityModel.py b/src/backend/base/langflow/components/models/PerplexityModel.py index 501d566af5d..b2478dfae2c 100644 --- a/src/backend/base/langflow/components/models/PerplexityModel.py +++ b/src/backend/base/langflow/components/models/PerplexityModel.py @@ -18,7 +18,7 @@ class PerplexityComponent(LCModelComponent): name="model_name", display_name="Model Name", advanced=False, - options=['llama-3-sonar-small-32k-online'], + options=["llama-3-sonar-small-32k-online"], value="llama-3-sonar-small-32k-online", ), SecretStrInput( @@ -28,7 +28,6 @@ class PerplexityComponent(LCModelComponent): advanced=False, ), FloatInput(name="temperature", display_name="Temperature", value=0.75), - ] def build_model(self) -> LanguageModel: # type: ignore[type-var] @@ -36,7 +35,6 @@ def build_model(self) -> LanguageModel: # type: ignore[type-var] temperature = self.temperature model = self.model_name - output = ChatPerplexity( model=model, temperature=temperature or 0.75, From 48ed6bc8d5af5e204cd128f164334bcada0a7556 Mon Sep 17 00:00:00 2001 From: Sai Kolasani Date: Wed, 14 Aug 2024 15:05:33 -0700 Subject: [PATCH 03/10] wip --- .../components/models/PerplexityModel.py | 17 ++++++++++---- .../src/icons/Perplexity/Perplexity.jsx | 21 ++++++++++++++++++ src/frontend/src/icons/Perplexity/index.tsx | 9 ++++++++ .../src/icons/Perplexity/perplexity.svg | Bin 0 -> 2116 bytes 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 src/frontend/src/icons/Perplexity/Perplexity.jsx create mode 100644 src/frontend/src/icons/Perplexity/index.tsx create mode 100644 src/frontend/src/icons/Perplexity/perplexity.svg diff --git a/src/backend/base/langflow/components/models/PerplexityModel.py b/src/backend/base/langflow/components/models/PerplexityModel.py index 501d566af5d..7c385e51a76 100644 --- a/src/backend/base/langflow/components/models/PerplexityModel.py +++ b/src/backend/base/langflow/components/models/PerplexityModel.py @@ -5,12 +5,21 @@ from langflow.field_typing import LanguageModel from langflow.io import FloatInput, SecretStrInput, DropdownInput +PERPLEXITY_MODEL_NAMES = [ + "llama-3.1-sonar-small-128k-online", + "llama-3.1-sonar-large-128k-online", + "llama-3.1-sonar-huge-128k-online", + "llama-3.1-sonar-small-128k-chat", + "llama-3.1-sonar-large-128k-chat", + "llama-3.1-8b-instruct", + "llama-3.1-70b-instruct", +] class PerplexityComponent(LCModelComponent): display_name = "Perplexity" description = "Generate text using Perplexity LLMs." - documentation = "https://python.langchain.com/docs/modules/model_io/models/llms/integrations/cohere" - icon = "Google" + documentation = "https://python.langchain.com/v0.2/docs/integrations/chat/perplexity/" + icon = "Perplexity" name = "PerplexityModel" inputs = LCModelComponent._base_inputs + [ @@ -18,8 +27,8 @@ class PerplexityComponent(LCModelComponent): name="model_name", display_name="Model Name", advanced=False, - options=['llama-3-sonar-small-32k-online'], - value="llama-3-sonar-small-32k-online", + options=PERPLEXITY_MODEL_NAMES, + value=PERPLEXITY_MODEL_NAMES[0], ), SecretStrInput( name="api_key", diff --git a/src/frontend/src/icons/Perplexity/Perplexity.jsx b/src/frontend/src/icons/Perplexity/Perplexity.jsx new file mode 100644 index 00000000000..44119f40c26 --- /dev/null +++ b/src/frontend/src/icons/Perplexity/Perplexity.jsx @@ -0,0 +1,21 @@ +const SvgPerplexity = (props) => ( + + + + + ); + + export default SvgPerplexity; diff --git a/src/frontend/src/icons/Perplexity/index.tsx b/src/frontend/src/icons/Perplexity/index.tsx new file mode 100644 index 00000000000..b415b5b39a2 --- /dev/null +++ b/src/frontend/src/icons/Perplexity/index.tsx @@ -0,0 +1,9 @@ +import React, { forwardRef } from "react"; +import PerplexitySVG from "./perplexity"; + +export const PerplexityIcon = forwardRef< + SVGSVGElement, + React.PropsWithChildren<{}> +>((props, ref) => { + return ; +}); \ No newline at end of file diff --git a/src/frontend/src/icons/Perplexity/perplexity.svg b/src/frontend/src/icons/Perplexity/perplexity.svg new file mode 100644 index 0000000000000000000000000000000000000000..307f257c0124ad92a93df4fef260beaf4e717370 GIT binary patch literal 2116 zcmbuAOHUg?5QO`uAab_Z_ah=4f)wQvDYh zsjjZB8UOluZX4U#t)1A5-P_6@H2z?xwzRFTM|*E)y1x50)xET-t?fxG&aAM^ud_YI zsZcgrd98H|n<#1_yt(dAcBi*nN50i~ty~M?^L=JtJ#wb^jecuIg0xk{i|+r6bEjO_ z%Kc|XYw_JG^Syqriu-2ITCvh-Yd@UJjow$f;PR~J!Yf%wIVxPM#<|DMeAVMW<95PZ zNX?I0`{G!cD&|*PE?s$M)=TTgDj{Fkxj0^n&r)-V4Sjm2_)l*?belWg7k$fx0z$5? zfxZ-Sr{~mKU6ozxS9_M;$Hxo`MP^!4JD=b+L@iW*p_QHDD$h1k{E0H+l3L$eDN!pX za2m}G*O!_dkB{d+AI)DLp$%0E_Egj=A5~Xg^@-T@dJhh*U5zjcsSvs+mQigQ!I}AE zo|&9-sy*o z-CB<3cHV)*?5kWpQ8XRu72j!fN^>X< zE_1nNCmNBt)id|C;DTOx4S~hl!t*qmZFJ$Q#E|+x%Dt=9S88@xL9@qVHEu?aPWP!| zSsl@_mryZy;Sn;|?uUpk6Q3zf67GLN`oFS#yQy2JYr=kjb zcd975wc4|aeT=^B0QP?69QmFUV@D7l5#ga2;Rl=$$eC8-1MpFh$SaL9F~m`wu0wt7 z*jDOfZ`Fa4_HEP`u0>zsLOa|;)x?f{68i)MT-9qfoeklO;fP&xhy Date: Wed, 14 Aug 2024 22:30:52 +0000 Subject: [PATCH 04/10] [autofix.ci] apply automated fixes --- .../src/icons/Perplexity/Perplexity.jsx | 38 +++++++++---------- src/frontend/src/icons/Perplexity/index.tsx | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/frontend/src/icons/Perplexity/Perplexity.jsx b/src/frontend/src/icons/Perplexity/Perplexity.jsx index 44119f40c26..5258f03d798 100644 --- a/src/frontend/src/icons/Perplexity/Perplexity.jsx +++ b/src/frontend/src/icons/Perplexity/Perplexity.jsx @@ -1,21 +1,21 @@ const SvgPerplexity = (props) => ( - - - - - ); + + + + +); - export default SvgPerplexity; +export default SvgPerplexity; diff --git a/src/frontend/src/icons/Perplexity/index.tsx b/src/frontend/src/icons/Perplexity/index.tsx index b415b5b39a2..d6103437cd2 100644 --- a/src/frontend/src/icons/Perplexity/index.tsx +++ b/src/frontend/src/icons/Perplexity/index.tsx @@ -6,4 +6,4 @@ export const PerplexityIcon = forwardRef< React.PropsWithChildren<{}> >((props, ref) => { return ; -}); \ No newline at end of file +}); From 542f0165ce3f9a213b2741085d40efcd3188b416 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 14 Aug 2024 22:41:56 +0000 Subject: [PATCH 05/10] [autofix.ci] apply automated fixes (attempt 2/3) --- src/backend/base/langflow/components/models/PerplexityModel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/base/langflow/components/models/PerplexityModel.py b/src/backend/base/langflow/components/models/PerplexityModel.py index 84d3665731f..25c013b978a 100644 --- a/src/backend/base/langflow/components/models/PerplexityModel.py +++ b/src/backend/base/langflow/components/models/PerplexityModel.py @@ -15,6 +15,7 @@ "llama-3.1-70b-instruct", ] + class PerplexityComponent(LCModelComponent): display_name = "Perplexity" description = "Generate text using Perplexity LLMs." From 3aa6c87c8cd336a0920507230a91a7b61e0f9ad9 Mon Sep 17 00:00:00 2001 From: Sai Kolasani Date: Thu, 15 Aug 2024 14:33:55 -0700 Subject: [PATCH 06/10] wip --- .../components/models/PerplexityModel.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/backend/base/langflow/components/models/PerplexityModel.py b/src/backend/base/langflow/components/models/PerplexityModel.py index 25c013b978a..bdbf371a970 100644 --- a/src/backend/base/langflow/components/models/PerplexityModel.py +++ b/src/backend/base/langflow/components/models/PerplexityModel.py @@ -5,15 +5,7 @@ from langflow.field_typing import LanguageModel from langflow.io import FloatInput, SecretStrInput, DropdownInput -PERPLEXITY_MODEL_NAMES = [ - "llama-3.1-sonar-small-128k-online", - "llama-3.1-sonar-large-128k-online", - "llama-3.1-sonar-huge-128k-online", - "llama-3.1-sonar-small-128k-chat", - "llama-3.1-sonar-large-128k-chat", - "llama-3.1-8b-instruct", - "llama-3.1-70b-instruct", -] + class PerplexityComponent(LCModelComponent): @@ -28,8 +20,16 @@ class PerplexityComponent(LCModelComponent): name="model_name", display_name="Model Name", advanced=False, - options=PERPLEXITY_MODEL_NAMES, - value=PERPLEXITY_MODEL_NAMES[0], + options=[ + "llama-3.1-sonar-small-128k-online", + "llama-3.1-sonar-large-128k-online", + "llama-3.1-sonar-huge-128k-online", + "llama-3.1-sonar-small-128k-chat", + "llama-3.1-sonar-large-128k-chat", + "llama-3.1-8b-instruct", + "llama-3.1-70b-instruct", + ], + value="llama-3.1-sonar-small-128k-online", ), SecretStrInput( name="api_key", From 30c84af2b2ad4ae95d0a0b73d1259a4c38787fbf Mon Sep 17 00:00:00 2001 From: Sai Kolasani Date: Thu, 15 Aug 2024 14:35:27 -0700 Subject: [PATCH 07/10] wip --- .../langflow/components/models/PerplexityModel.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/backend/base/langflow/components/models/PerplexityModel.py b/src/backend/base/langflow/components/models/PerplexityModel.py index bdbf371a970..21341a99beb 100644 --- a/src/backend/base/langflow/components/models/PerplexityModel.py +++ b/src/backend/base/langflow/components/models/PerplexityModel.py @@ -21,13 +21,13 @@ class PerplexityComponent(LCModelComponent): display_name="Model Name", advanced=False, options=[ - "llama-3.1-sonar-small-128k-online", - "llama-3.1-sonar-large-128k-online", - "llama-3.1-sonar-huge-128k-online", - "llama-3.1-sonar-small-128k-chat", - "llama-3.1-sonar-large-128k-chat", - "llama-3.1-8b-instruct", - "llama-3.1-70b-instruct", + "llama-3.1-sonar-small-128k-online", + "llama-3.1-sonar-large-128k-online", + "llama-3.1-sonar-huge-128k-online", + "llama-3.1-sonar-small-128k-chat", + "llama-3.1-sonar-large-128k-chat", + "llama-3.1-8b-instruct", + "llama-3.1-70b-instruct", ], value="llama-3.1-sonar-small-128k-online", ), From 7d1b13862ca5ff60dc97350961019ba39325df85 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 21:37:10 +0000 Subject: [PATCH 08/10] [autofix.ci] apply automated fixes --- src/backend/base/langflow/components/models/PerplexityModel.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/backend/base/langflow/components/models/PerplexityModel.py b/src/backend/base/langflow/components/models/PerplexityModel.py index 21341a99beb..e6eb5756eea 100644 --- a/src/backend/base/langflow/components/models/PerplexityModel.py +++ b/src/backend/base/langflow/components/models/PerplexityModel.py @@ -6,8 +6,6 @@ from langflow.io import FloatInput, SecretStrInput, DropdownInput - - class PerplexityComponent(LCModelComponent): display_name = "Perplexity" description = "Generate text using Perplexity LLMs." From 22879355ea50d1f532508959bfab134bc7a4417c Mon Sep 17 00:00:00 2001 From: Sai Kolasani Date: Thu, 15 Aug 2024 15:28:29 -0700 Subject: [PATCH 09/10] wip --- .../components/models/PerplexityModel.py | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/components/models/PerplexityModel.py b/src/backend/base/langflow/components/models/PerplexityModel.py index e6eb5756eea..7265db9b47e 100644 --- a/src/backend/base/langflow/components/models/PerplexityModel.py +++ b/src/backend/base/langflow/components/models/PerplexityModel.py @@ -3,7 +3,7 @@ from langflow.base.models.model import LCModelComponent from langflow.field_typing import LanguageModel -from langflow.io import FloatInput, SecretStrInput, DropdownInput +from langflow.io import FloatInput, SecretStrInput, DropdownInput, IntInput class PerplexityComponent(LCModelComponent): @@ -29,6 +29,11 @@ class PerplexityComponent(LCModelComponent): ], value="llama-3.1-sonar-small-128k-online", ), + IntInput( + name="max_output_tokens", + display_name="Max Output Tokens", + info="The maximum number of tokens to generate.", + ), SecretStrInput( name="api_key", display_name="Perplexity API Key", @@ -36,17 +41,43 @@ class PerplexityComponent(LCModelComponent): advanced=False, ), FloatInput(name="temperature", display_name="Temperature", value=0.75), + FloatInput( + name="top_p", + display_name="Top P", + info="The maximum cumulative probability of tokens to consider when sampling.", + advanced=True, + ), + IntInput( + name="n", + display_name="N", + info="Number of chat completions to generate for each prompt. Note that the API may not return the full n completions if duplicates are generated.", + advanced=True, + ), + IntInput( + name="top_k", + display_name="Top K", + info="Decode using top-k sampling: consider the set of top_k most probable tokens. Must be positive.", + advanced=True, + ), ] def build_model(self) -> LanguageModel: # type: ignore[type-var] api_key = SecretStr(self.api_key).get_secret_value() temperature = self.temperature model = self.model_name + max_output_tokens = self.max_output_tokens + top_k = self.top_k + top_p = self.top_p + n = self.n output = ChatPerplexity( model=model, temperature=temperature or 0.75, pplx_api_key=api_key, + top_k=top_k or None, + top_p=top_p or None, + n=n or 1, + max_output_tokens=max_output_tokens, ) return output # type: ignore From ada74a4bc7d4a05cc2abfbc52abeecc8f92e9d29 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Mon, 19 Aug 2024 18:17:25 -0300 Subject: [PATCH 10/10] add icon to icon vector --- src/frontend/package-lock.json | 1 + src/frontend/src/utils/styleUtils.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/frontend/package-lock.json b/src/frontend/package-lock.json index db0e15228cd..f150e6b429d 100644 --- a/src/frontend/package-lock.json +++ b/src/frontend/package-lock.json @@ -1079,6 +1079,7 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", + "extraneous": true, "inBundle": true, "license": "MIT", "engines": { diff --git a/src/frontend/src/utils/styleUtils.ts b/src/frontend/src/utils/styleUtils.ts index 0cc99b01212..f1607acb55f 100644 --- a/src/frontend/src/utils/styleUtils.ts +++ b/src/frontend/src/utils/styleUtils.ts @@ -1,4 +1,5 @@ import { AIMLIcon } from "@/icons/AIML"; +import Perplexity from "@/icons/Perplexity/Perplexity"; import { AthenaIcon } from "@/icons/athena/index"; import { freezeAllIcon } from "@/icons/freezeAll"; import { @@ -599,4 +600,5 @@ export const nodeIconsLucide: iconsType = { athenaIcon: AthenaIcon, OptionIcon: OptionIcon, Option: OptionIcon, + Perplexity, };