-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
openai[minor]: implement langchain-openai package #15503
Merged
Merged
Changes from 61 commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
20694ac
init
efriis 48cbc10
add openai
efriis 57d2970
add numpy
efriis 8c43bf3
Merge branch 'master' into erick/partner-openai
efriis 134b092
embeddings
efriis e309378
add back transformers option
efriis edb0851
chat model
efriis 6f5eb50
downgrade mypy again
efriis d4fceed
x
efriis 24e1eac
unit tests
efriis ad6bce5
remove duplicate test
efriis e6a8c25
more duplicate test
efriis 26c395c
conversion
efriis 1aa1dcb
Merge branch 'master' into erick/partner-openai
efriis 01bd344
x
efriis 9b1778b
Merge branch 'master' into erick/partner-openai
efriis f11d9ec
lint
efriis 361d6e8
x
efriis 61edd7e
lint core
efriis 6c22e81
x
efriis c70d6c0
fix import test
efriis 7b1204f
Merge branch 'master' into erick/partner-openai
efriis 26620d8
chatopenai start
efriis 81b0bb6
cookbook ChatOpenAI
efriis 25e7262
docs ChatOpenAI
efriis 00efbf4
docs ChatOpenAI
efriis 7f385f2
docs ChatPromptTemplate
efriis 01ed344
docs ChatPromptTemplate
efriis 759cf14
docs ChatOpenAI
efriis fcfc090
docs OpenAI
efriis 3254233
docs OpenAI
efriis fe7425f
docs OpenAIEmbeddings
efriis d27bf40
integration tests
efriis 8e81c79
docs in separate pr
efriis 32e207a
rm _utils
efriis 0f06c8a
Merge branch 'master' into erick/partner-openai
efriis 287eec7
ser
efriis 970034f
reorg
efriis caa03ab
init
efriis 8aaf50e
import test
efriis 778fe39
tests
efriis 92945d2
integration tests
efriis c389fbc
lint
efriis 4b8ed72
mypy
efriis 5e49c5b
fix
efriis cee3f6a
no more chat unit
efriis 0abb3e0
Merge branch 'master' into erick/partner-openai
efriis 06b2f3c
deps
efriis 0827b72
deps
efriis bf766b3
deprecations
efriis 0f7b35f
format
efriis e4a64fb
debug
efriis 4a29380
rm print
efriis fa73df4
deps
efriis fefec8f
tests
efriis 8c8b0df
t
efriis b4b6f71
-
efriis fe97a5c
simplify
efriis be6a46e
oops
efriis 6277cdc
protect
efriis 07fd7e9
delete
efriis 5f05ad9
x
efriis 390bb77
x
efriis fb8ddc7
warn
efriis 412d059
secrets
efriis 1e79455
Merge branch 'master' into erick/partner-openai
efriis File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
Union, | ||
) | ||
|
||
from langchain_core._api.deprecation import deprecated | ||
from langchain_core.callbacks import ( | ||
AsyncCallbackManagerForLLMRun, | ||
CallbackManagerForLLMRun, | ||
|
@@ -724,6 +725,7 @@ def max_tokens_for_prompt(self, prompt: str) -> int: | |
return self.max_context_size - num_tokens | ||
|
||
|
||
@deprecated(since="0.1.0", removal="0.2.0", alternative="langchain_openai.OpenAI") | ||
class OpenAI(BaseOpenAI): | ||
"""OpenAI large language models. | ||
|
||
|
@@ -750,6 +752,7 @@ def _invocation_params(self) -> Dict[str, Any]: | |
return {**{"model": self.model_name}, **super()._invocation_params} | ||
|
||
|
||
@deprecated(since="0.1.0", removal="0.2.0", alternative="langchain_openai.AzureOpenAI") | ||
class AzureOpenAI(BaseOpenAI): | ||
"""Azure-specific OpenAI large language models. | ||
|
||
|
@@ -953,6 +956,7 @@ def lc_attributes(self) -> Dict[str, Any]: | |
} | ||
|
||
|
||
@deprecated(since="0.1.0", removal="0.2.0", alternative="langchain_openai.ChatOpenAI") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to discuss. This isn't a 1:1 replacement in 0.2 |
||
class OpenAIChat(BaseLLM): | ||
"""OpenAI Chat large language models. | ||
|
||
|
66 changes: 15 additions & 51 deletions
66
libs/community/langchain_community/utils/openai_functions.py
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved function calling stuff to core/utils/function_calling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,15 @@ | ||
from typing import Literal, Optional, Type, TypedDict | ||
|
||
from langchain_core.pydantic_v1 import BaseModel | ||
from langchain_core.utils.json_schema import dereference_refs | ||
|
||
|
||
class FunctionDescription(TypedDict): | ||
"""Representation of a callable function to the OpenAI API.""" | ||
|
||
name: str | ||
"""The name of the function.""" | ||
description: str | ||
"""A description of the function.""" | ||
parameters: dict | ||
"""The parameters of the function.""" | ||
|
||
|
||
class ToolDescription(TypedDict): | ||
"""Representation of a callable function to the OpenAI API.""" | ||
|
||
type: Literal["function"] | ||
function: FunctionDescription | ||
|
||
|
||
def convert_pydantic_to_openai_function( | ||
model: Type[BaseModel], | ||
*, | ||
name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
) -> FunctionDescription: | ||
"""Converts a Pydantic model to a function description for the OpenAI API.""" | ||
schema = dereference_refs(model.schema()) | ||
schema.pop("definitions", None) | ||
return { | ||
"name": name or schema["title"], | ||
"description": description or schema["description"], | ||
"parameters": schema, | ||
} | ||
|
||
|
||
def convert_pydantic_to_openai_tool( | ||
model: Type[BaseModel], | ||
*, | ||
name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
) -> ToolDescription: | ||
"""Converts a Pydantic model to a function description for the OpenAI API.""" | ||
function = convert_pydantic_to_openai_function( | ||
model, name=name, description=description | ||
) | ||
return {"type": "function", "function": function} | ||
# these stubs are just for backwards compatibility | ||
|
||
from langchain_core.utils.function_calling import ( | ||
FunctionDescription, | ||
ToolDescription, | ||
convert_pydantic_to_openai_function, | ||
convert_pydantic_to_openai_tool, | ||
) | ||
|
||
__all__ = [ | ||
"FunctionDescription", | ||
"ToolDescription", | ||
"convert_pydantic_to_openai_function", | ||
"convert_pydantic_to_openai_tool", | ||
] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
causes a decent number of deprecation warnings in unit tests, but still important to test community one before removal.