langchain-githubcopilot-chat 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langchain_githubcopilot_chat/__init__.py +31 -0
- langchain_githubcopilot_chat/chat_models.py +923 -0
- langchain_githubcopilot_chat/document_loaders.py +73 -0
- langchain_githubcopilot_chat/embeddings.py +96 -0
- langchain_githubcopilot_chat/py.typed +0 -0
- langchain_githubcopilot_chat/retrievers.py +107 -0
- langchain_githubcopilot_chat/toolkits.py +72 -0
- langchain_githubcopilot_chat/tools.py +94 -0
- langchain_githubcopilot_chat/vectorstores.py +439 -0
- langchain_githubcopilot_chat-0.1.0.dist-info/LICENSE +21 -0
- langchain_githubcopilot_chat-0.1.0.dist-info/METADATA +70 -0
- langchain_githubcopilot_chat-0.1.0.dist-info/RECORD +13 -0
- langchain_githubcopilot_chat-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""GithubcopilotChat document loader."""
|
|
2
|
+
|
|
3
|
+
from typing import Iterator
|
|
4
|
+
|
|
5
|
+
from langchain_core.document_loaders.base import BaseLoader
|
|
6
|
+
from langchain_core.documents import Document
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GithubcopilotChatLoader(BaseLoader):
|
|
10
|
+
# TODO: Replace all TODOs in docstring. See example docstring:
|
|
11
|
+
# https://github.com/langchain-ai/langchain/blob/869523ad728e6b76d77f170cce13925b4ebc3c1e/libs/community/langchain_community/document_loaders/recursive_url_loader.py#L54
|
|
12
|
+
"""
|
|
13
|
+
GithubcopilotChat document loader integration
|
|
14
|
+
|
|
15
|
+
# TODO: Replace with relevant packages, env vars.
|
|
16
|
+
Setup:
|
|
17
|
+
Install ``langchain-githubcopilot-chat`` and set environment variable ``GITHUBCOPILOTCHAT_API_KEY``.
|
|
18
|
+
|
|
19
|
+
.. code-block:: bash
|
|
20
|
+
|
|
21
|
+
pip install -U langchain-githubcopilot-chat
|
|
22
|
+
export GITHUBCOPILOTCHAT_API_KEY="your-api-key"
|
|
23
|
+
|
|
24
|
+
# TODO: Replace with relevant init params.
|
|
25
|
+
Instantiate:
|
|
26
|
+
.. code-block:: python
|
|
27
|
+
|
|
28
|
+
from langchain_community.document_loaders import GithubcopilotChatLoader
|
|
29
|
+
|
|
30
|
+
loader = GithubcopilotChatLoader(
|
|
31
|
+
# required params = ...
|
|
32
|
+
# other params = ...
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
Lazy load:
|
|
36
|
+
.. code-block:: python
|
|
37
|
+
|
|
38
|
+
docs = []
|
|
39
|
+
docs_lazy = loader.lazy_load()
|
|
40
|
+
|
|
41
|
+
# async variant:
|
|
42
|
+
# docs_lazy = await loader.alazy_load()
|
|
43
|
+
|
|
44
|
+
for doc in docs_lazy:
|
|
45
|
+
docs.append(doc)
|
|
46
|
+
print(docs[0].page_content[:100])
|
|
47
|
+
print(docs[0].metadata)
|
|
48
|
+
|
|
49
|
+
.. code-block:: python
|
|
50
|
+
|
|
51
|
+
TODO: Example output
|
|
52
|
+
|
|
53
|
+
# TODO: Delete if async load is not implemented
|
|
54
|
+
Async load:
|
|
55
|
+
.. code-block:: python
|
|
56
|
+
|
|
57
|
+
docs = await loader.aload()
|
|
58
|
+
print(docs[0].page_content[:100])
|
|
59
|
+
print(docs[0].metadata)
|
|
60
|
+
|
|
61
|
+
.. code-block:: python
|
|
62
|
+
|
|
63
|
+
TODO: Example output
|
|
64
|
+
|
|
65
|
+
""" # noqa: E501
|
|
66
|
+
|
|
67
|
+
# TODO: This method must be implemented to load documents.
|
|
68
|
+
# Do not implement load(), a default implementation is already available.
|
|
69
|
+
def lazy_load(self) -> Iterator[Document]:
|
|
70
|
+
raise NotImplementedError()
|
|
71
|
+
|
|
72
|
+
# TODO: Implement if you would like to change default BaseLoader implementation
|
|
73
|
+
# async def alazy_load(self) -> AsyncIterator[Document]:
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from langchain_core.embeddings import Embeddings
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class GithubcopilotChatEmbeddings(Embeddings):
|
|
7
|
+
"""GithubcopilotChat embedding model integration.
|
|
8
|
+
|
|
9
|
+
# TODO: Replace with relevant packages, env vars.
|
|
10
|
+
Setup:
|
|
11
|
+
Install ``langchain-githubcopilot-chat`` and set environment variable
|
|
12
|
+
``GITHUBCOPILOTCHAT_API_KEY``.
|
|
13
|
+
|
|
14
|
+
.. code-block:: bash
|
|
15
|
+
|
|
16
|
+
pip install -U langchain-githubcopilot-chat
|
|
17
|
+
export GITHUBCOPILOTCHAT_API_KEY="your-api-key"
|
|
18
|
+
|
|
19
|
+
# TODO: Populate with relevant params.
|
|
20
|
+
Key init args — completion params:
|
|
21
|
+
model: str
|
|
22
|
+
Name of GithubcopilotChat model to use.
|
|
23
|
+
|
|
24
|
+
See full list of supported init args and their descriptions in the params section.
|
|
25
|
+
|
|
26
|
+
# TODO: Replace with relevant init params.
|
|
27
|
+
Instantiate:
|
|
28
|
+
.. code-block:: python
|
|
29
|
+
|
|
30
|
+
from langchain_githubcopilot_chat import GithubcopilotChatEmbeddings
|
|
31
|
+
|
|
32
|
+
embed = GithubcopilotChatEmbeddings(
|
|
33
|
+
model="...",
|
|
34
|
+
# api_key="...",
|
|
35
|
+
# other params...
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
Embed single text:
|
|
39
|
+
.. code-block:: python
|
|
40
|
+
|
|
41
|
+
input_text = "The meaning of life is 42"
|
|
42
|
+
embed.embed_query(input_text)
|
|
43
|
+
|
|
44
|
+
.. code-block:: python
|
|
45
|
+
|
|
46
|
+
# TODO: Example output.
|
|
47
|
+
|
|
48
|
+
# TODO: Delete if token-level streaming isn't supported.
|
|
49
|
+
Embed multiple text:
|
|
50
|
+
.. code-block:: python
|
|
51
|
+
|
|
52
|
+
input_texts = ["Document 1...", "Document 2..."]
|
|
53
|
+
embed.embed_documents(input_texts)
|
|
54
|
+
|
|
55
|
+
.. code-block:: python
|
|
56
|
+
|
|
57
|
+
# TODO: Example output.
|
|
58
|
+
|
|
59
|
+
# TODO: Delete if native async isn't supported.
|
|
60
|
+
Async:
|
|
61
|
+
.. code-block:: python
|
|
62
|
+
|
|
63
|
+
await embed.aembed_query(input_text)
|
|
64
|
+
|
|
65
|
+
# multiple:
|
|
66
|
+
# await embed.aembed_documents(input_texts)
|
|
67
|
+
|
|
68
|
+
.. code-block:: python
|
|
69
|
+
|
|
70
|
+
# TODO: Example output.
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
def __init__(self, model: str):
|
|
75
|
+
self.model = model
|
|
76
|
+
|
|
77
|
+
def embed_documents(self, texts: List[str]) -> List[List[float]]:
|
|
78
|
+
"""Embed search docs."""
|
|
79
|
+
return [[0.5, 0.6, 0.7] for _ in texts]
|
|
80
|
+
|
|
81
|
+
def embed_query(self, text: str) -> List[float]:
|
|
82
|
+
"""Embed query text."""
|
|
83
|
+
return self.embed_documents([text])[0]
|
|
84
|
+
|
|
85
|
+
# optional: add custom async implementations here
|
|
86
|
+
# you can also delete these, and the base class will
|
|
87
|
+
# use the default implementation, which calls the sync
|
|
88
|
+
# version in an async executor:
|
|
89
|
+
|
|
90
|
+
# async def aembed_documents(self, texts: List[str]) -> List[List[float]]:
|
|
91
|
+
# """Asynchronous Embed search docs."""
|
|
92
|
+
# ...
|
|
93
|
+
|
|
94
|
+
# async def aembed_query(self, text: str) -> List[float]:
|
|
95
|
+
# """Asynchronous Embed query text."""
|
|
96
|
+
# ...
|
|
File without changes
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""GithubcopilotChat retrievers."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, List
|
|
4
|
+
|
|
5
|
+
from langchain_core.callbacks import CallbackManagerForRetrieverRun
|
|
6
|
+
from langchain_core.documents import Document
|
|
7
|
+
from langchain_core.retrievers import BaseRetriever
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GithubcopilotChatRetriever(BaseRetriever):
|
|
11
|
+
# TODO: Replace all TODOs in docstring. See example docstring:
|
|
12
|
+
# https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/retrievers/tavily_search_api.py#L17
|
|
13
|
+
"""GithubcopilotChat retriever.
|
|
14
|
+
|
|
15
|
+
# TODO: Replace with relevant packages, env vars, etc.
|
|
16
|
+
Setup:
|
|
17
|
+
Install ``langchain-githubcopilot-chat`` and set environment variable
|
|
18
|
+
``GITHUBCOPILOTCHAT_API_KEY``.
|
|
19
|
+
|
|
20
|
+
.. code-block:: bash
|
|
21
|
+
|
|
22
|
+
pip install -U langchain-githubcopilot-chat
|
|
23
|
+
export GITHUBCOPILOTCHAT_API_KEY="your-api-key"
|
|
24
|
+
|
|
25
|
+
# TODO: Populate with relevant params.
|
|
26
|
+
Key init args:
|
|
27
|
+
arg 1: type
|
|
28
|
+
description
|
|
29
|
+
arg 2: type
|
|
30
|
+
description
|
|
31
|
+
|
|
32
|
+
# TODO: Replace with relevant init params.
|
|
33
|
+
Instantiate:
|
|
34
|
+
.. code-block:: python
|
|
35
|
+
|
|
36
|
+
from langchain-githubcopilot-chat import GithubcopilotChatRetriever
|
|
37
|
+
|
|
38
|
+
retriever = GithubcopilotChatRetriever(
|
|
39
|
+
# ...
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
Usage:
|
|
43
|
+
.. code-block:: python
|
|
44
|
+
|
|
45
|
+
query = "..."
|
|
46
|
+
|
|
47
|
+
retriever.invoke(query)
|
|
48
|
+
|
|
49
|
+
.. code-block:: none
|
|
50
|
+
|
|
51
|
+
# TODO: Example output.
|
|
52
|
+
|
|
53
|
+
Use within a chain:
|
|
54
|
+
.. code-block:: python
|
|
55
|
+
|
|
56
|
+
from langchain_core.output_parsers import StrOutputParser
|
|
57
|
+
from langchain_core.prompts import ChatPromptTemplate
|
|
58
|
+
from langchain_core.runnables import RunnablePassthrough
|
|
59
|
+
from langchain_openai import ChatOpenAI
|
|
60
|
+
|
|
61
|
+
prompt = ChatPromptTemplate.from_template(
|
|
62
|
+
\"\"\"Answer the question based only on the context provided.
|
|
63
|
+
|
|
64
|
+
Context: {context}
|
|
65
|
+
|
|
66
|
+
Question: {question}\"\"\"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
llm = ChatOpenAI(model="gpt-3.5-turbo-0125")
|
|
70
|
+
|
|
71
|
+
def format_docs(docs):
|
|
72
|
+
return "\\n\\n".join(doc.page_content for doc in docs)
|
|
73
|
+
|
|
74
|
+
chain = (
|
|
75
|
+
{"context": retriever | format_docs, "question": RunnablePassthrough()}
|
|
76
|
+
| prompt
|
|
77
|
+
| llm
|
|
78
|
+
| StrOutputParser()
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
chain.invoke("...")
|
|
82
|
+
|
|
83
|
+
.. code-block:: none
|
|
84
|
+
|
|
85
|
+
# TODO: Example output.
|
|
86
|
+
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
k: int = 3
|
|
90
|
+
|
|
91
|
+
# TODO: This method must be implemented to retrieve documents.
|
|
92
|
+
def _get_relevant_documents(
|
|
93
|
+
self, query: str, *, run_manager: CallbackManagerForRetrieverRun, **kwargs: Any
|
|
94
|
+
) -> List[Document]:
|
|
95
|
+
k = kwargs.get("k", self.k)
|
|
96
|
+
return [
|
|
97
|
+
Document(page_content=f"Result {i} for query: {query}") for i in range(k)
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
# optional: add custom async implementations here
|
|
101
|
+
# async def _aget_relevant_documents(
|
|
102
|
+
# self,
|
|
103
|
+
# query: str,
|
|
104
|
+
# *,
|
|
105
|
+
# run_manager: AsyncCallbackManagerForRetrieverRun,
|
|
106
|
+
# **kwargs: Any,
|
|
107
|
+
# ) -> List[Document]: ...
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""GithubcopilotChat toolkits."""
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from langchain_core.tools import BaseTool, BaseToolkit
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class GithubcopilotChatToolkit(BaseToolkit):
|
|
9
|
+
# TODO: Replace all TODOs in docstring. See example docstring:
|
|
10
|
+
# https://github.com/langchain-ai/langchain/blob/c123cb2b304f52ab65db4714eeec46af69a861ec/libs/community/langchain_community/agent_toolkits/sql/toolkit.py#L19
|
|
11
|
+
"""GithubcopilotChat toolkit.
|
|
12
|
+
|
|
13
|
+
# TODO: Replace with relevant packages, env vars, etc.
|
|
14
|
+
Setup:
|
|
15
|
+
Install ``langchain-githubcopilot-chat`` and set environment variable ``GITHUBCOPILOTCHAT_API_KEY``.
|
|
16
|
+
|
|
17
|
+
.. code-block:: bash
|
|
18
|
+
|
|
19
|
+
pip install -U langchain-githubcopilot-chat
|
|
20
|
+
export GITHUBCOPILOTCHAT_API_KEY="your-api-key"
|
|
21
|
+
|
|
22
|
+
# TODO: Populate with relevant params.
|
|
23
|
+
Key init args:
|
|
24
|
+
arg 1: type
|
|
25
|
+
description
|
|
26
|
+
arg 2: type
|
|
27
|
+
description
|
|
28
|
+
|
|
29
|
+
# TODO: Replace with relevant init params.
|
|
30
|
+
Instantiate:
|
|
31
|
+
.. code-block:: python
|
|
32
|
+
|
|
33
|
+
from langchain-githubcopilot-chat import GithubcopilotChatToolkit
|
|
34
|
+
|
|
35
|
+
toolkit = GithubcopilotChatToolkit(
|
|
36
|
+
# ...
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
Tools:
|
|
40
|
+
.. code-block:: python
|
|
41
|
+
|
|
42
|
+
toolkit.get_tools()
|
|
43
|
+
|
|
44
|
+
.. code-block:: none
|
|
45
|
+
|
|
46
|
+
# TODO: Example output.
|
|
47
|
+
|
|
48
|
+
Use within an agent:
|
|
49
|
+
.. code-block:: python
|
|
50
|
+
|
|
51
|
+
from langgraph.prebuilt import create_react_agent
|
|
52
|
+
|
|
53
|
+
agent_executor = create_react_agent(llm, tools)
|
|
54
|
+
|
|
55
|
+
example_query = "..."
|
|
56
|
+
|
|
57
|
+
events = agent_executor.stream(
|
|
58
|
+
{"messages": [("user", example_query)]},
|
|
59
|
+
stream_mode="values",
|
|
60
|
+
)
|
|
61
|
+
for event in events:
|
|
62
|
+
event["messages"][-1].pretty_print()
|
|
63
|
+
|
|
64
|
+
.. code-block:: none
|
|
65
|
+
|
|
66
|
+
# TODO: Example output.
|
|
67
|
+
|
|
68
|
+
""" # noqa: E501
|
|
69
|
+
|
|
70
|
+
# TODO: This method must be implemented to list tools.
|
|
71
|
+
def get_tools(self) -> List[BaseTool]:
|
|
72
|
+
raise NotImplementedError()
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""GithubcopilotChat tools."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional, Type
|
|
4
|
+
|
|
5
|
+
from langchain_core.callbacks import (
|
|
6
|
+
CallbackManagerForToolRun,
|
|
7
|
+
)
|
|
8
|
+
from langchain_core.tools import BaseTool
|
|
9
|
+
from pydantic import BaseModel, Field
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class GithubcopilotChatToolInput(BaseModel):
|
|
13
|
+
"""Input schema for GithubcopilotChat tool.
|
|
14
|
+
|
|
15
|
+
This docstring is **not** part of what is sent to the model when performing tool
|
|
16
|
+
calling. The Field default values and descriptions **are** part of what is sent to
|
|
17
|
+
the model when performing tool calling.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
# TODO: Add input args and descriptions.
|
|
21
|
+
a: int = Field(..., description="first number to add")
|
|
22
|
+
b: int = Field(..., description="second number to add")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class GithubcopilotChatTool(BaseTool): # type: ignore[override]
|
|
26
|
+
"""GithubcopilotChat tool.
|
|
27
|
+
|
|
28
|
+
Setup:
|
|
29
|
+
# TODO: Replace with relevant packages, env vars.
|
|
30
|
+
Install ``langchain-githubcopilot-chat`` and set environment variable ``GITHUBCOPILOTCHAT_API_KEY``.
|
|
31
|
+
|
|
32
|
+
.. code-block:: bash
|
|
33
|
+
|
|
34
|
+
pip install -U langchain-githubcopilot-chat
|
|
35
|
+
export GITHUBCOPILOTCHAT_API_KEY="your-api-key"
|
|
36
|
+
|
|
37
|
+
Instantiation:
|
|
38
|
+
.. code-block:: python
|
|
39
|
+
|
|
40
|
+
tool = GithubcopilotChatTool(
|
|
41
|
+
# TODO: init params
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
Invocation with args:
|
|
45
|
+
.. code-block:: python
|
|
46
|
+
|
|
47
|
+
# TODO: invoke args
|
|
48
|
+
tool.invoke({...})
|
|
49
|
+
|
|
50
|
+
.. code-block:: python
|
|
51
|
+
|
|
52
|
+
# TODO: output of invocation
|
|
53
|
+
|
|
54
|
+
Invocation with ToolCall:
|
|
55
|
+
|
|
56
|
+
.. code-block:: python
|
|
57
|
+
|
|
58
|
+
# TODO: invoke args
|
|
59
|
+
tool.invoke({"args": {...}, "id": "1", "name": tool.name, "type": "tool_call"})
|
|
60
|
+
|
|
61
|
+
.. code-block:: python
|
|
62
|
+
|
|
63
|
+
# TODO: output of invocation
|
|
64
|
+
|
|
65
|
+
""" # noqa: E501
|
|
66
|
+
|
|
67
|
+
# TODO: Set tool name and description
|
|
68
|
+
name: str = "TODO: Tool name"
|
|
69
|
+
"""The name that is passed to the model when performing tool calling."""
|
|
70
|
+
description: str = "TODO: Tool description."
|
|
71
|
+
"""The description that is passed to the model when performing tool calling."""
|
|
72
|
+
args_schema: Type[BaseModel] = GithubcopilotChatToolInput
|
|
73
|
+
"""The schema that is passed to the model when performing tool calling."""
|
|
74
|
+
|
|
75
|
+
# TODO: Add any other init params for the tool.
|
|
76
|
+
# param1: Optional[str]
|
|
77
|
+
# """param1 determines foobar"""
|
|
78
|
+
|
|
79
|
+
# TODO: Replaced (a, b) with real tool arguments.
|
|
80
|
+
def _run(
|
|
81
|
+
self, a: int, b: int, *, run_manager: Optional[CallbackManagerForToolRun] = None
|
|
82
|
+
) -> str:
|
|
83
|
+
return str(a + b + 80)
|
|
84
|
+
|
|
85
|
+
# TODO: Implement if tool has native async functionality, otherwise delete.
|
|
86
|
+
|
|
87
|
+
# async def _arun(
|
|
88
|
+
# self,
|
|
89
|
+
# a: int,
|
|
90
|
+
# b: int,
|
|
91
|
+
# *,
|
|
92
|
+
# run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
|
93
|
+
# ) -> str:
|
|
94
|
+
# ...
|