Skip to content

Commit

Permalink
Update the version to 0.1.24 (#347)
Browse files Browse the repository at this point in the history
Signed-off-by: SimFG <[email protected]>
  • Loading branch information
SimFG authored May 15, 2023
1 parent 768a911 commit dd0f16f
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 20 deletions.
36 changes: 36 additions & 0 deletions docs/release_note.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@ To read the following content, you need to understand the basic use of GPTCache,
- [Readme doc](https://github.com/zilliztech/GPTCache)
- [Usage doc](https://github.com/zilliztech/GPTCache/blob/main/docs/usage.md)

## v0.1.24 (2023.5.15)

1. Support the langchain embedding

```python
from gptcache.embedding import LangChain
from langchain.embeddings.openai import OpenAIEmbeddings

test_sentence = 'Hello, world.'
embeddings = OpenAIEmbeddings(model="your-embeddings-deployment-name")
encoder = LangChain(embeddings=embeddings)
embed = encoder.to_embeddings(test_sentence)
```

2. Add gptcache client

```python
from gptcache import Client

client = Client()
client.put("Hi", "Hi back")
ans = client.get("Hi")
```

3. Support pgvector as vector store

```python
from gptcache.manager import manager_factory

data_manager = manager_factory("sqlite,pgvector", vector_params={"dimension": 10})
```

4. Add the GPTCache server doc

reference: https://github.com/zilliztech/GPTCache/blob/main/docs/usage.md#Build-GPTCache-server

## v0.1.23 (2023.5.11)

1. Support the session for the `LangChainLLMs`
Expand Down
17 changes: 9 additions & 8 deletions gptcache/adapter/openai.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import time
from typing import Iterator, Any

import os
import openai

import base64
import os
import time
from io import BytesIO
from typing import Iterator, Any

from gptcache.utils import import_pillow
from gptcache.utils.error import CacheError
from gptcache.adapter.adapter import adapt
from gptcache.manager.scalar_data.base import Answer, DataType
from gptcache.utils import import_openai, import_pillow
from gptcache.utils.error import CacheError
from gptcache.utils.response import (
get_stream_message_from_openai_answer,
get_message_from_openai_answer,
Expand All @@ -20,6 +17,10 @@
get_audio_text_from_openai_answer,
)

import_openai()

import openai # pylint: disable=C0413


class ChatCompletion(openai.ChatCompletion):
"""Openai ChatCompletion Wrapper
Expand Down
6 changes: 4 additions & 2 deletions gptcache/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os
from typing import Optional, List, Any

import openai

from gptcache.config import Config
from gptcache.embedding.string import to_embeddings as string_embedding
from gptcache.manager import get_data_manager
Expand All @@ -13,6 +11,7 @@
from gptcache.report import Report
from gptcache.similarity_evaluation import ExactMatchEvaluation
from gptcache.similarity_evaluation import SimilarityEvaluation
from gptcache.utils import import_openai
from gptcache.utils.cache_func import cache_all
from gptcache.utils.log import gptcache_log

Expand Down Expand Up @@ -109,6 +108,9 @@ def flush(self):

@staticmethod
def set_openai_key():
import_openai()
import openai # pylint: disable=C0415

openai.api_key = os.getenv("OPENAI_API_KEY")


Expand Down
2 changes: 1 addition & 1 deletion gptcache/embedding/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = ["OpenAI", "Huggingface", "SBERT", "Cohere", "Onnx", "FastText", "Data2VecAudio", "Timm", "ViT"]
__all__ = ["OpenAI", "Huggingface", "SBERT", "Cohere", "Onnx", "FastText", "Data2VecAudio", "Timm", "ViT", "LangChain"]


from gptcache.utils.lazy_import import LazyImport
Expand Down
8 changes: 6 additions & 2 deletions gptcache/embedding/openai.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import numpy as np
import openai
import os

import numpy as np

from gptcache.embedding.base import BaseEmbedding
from gptcache.utils import import_openai

import_openai()

import openai # pylint: disable=C0413

class OpenAI(BaseEmbedding):
"""Generate text embedding for given text using OpenAI.
Expand Down
10 changes: 5 additions & 5 deletions gptcache/manager/vector_data/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def get(name, **kwargs):
collection_name = kwargs.get("collection_name", COLLECTION_NAME)
index_params = kwargs.get("index_params", PGVECTOR_INDEX_PARAMS)
vector_base = PGVector(
dimension = dimension,
top_k = top_k,
url = url,
collection_name = collection_name,
index_params = index_params
dimension=dimension,
top_k=top_k,
url=url,
collection_name=collection_name,
index_params=index_params
)
else:
raise NotFoundError("vector store", name)
Expand Down
6 changes: 6 additions & 0 deletions gptcache/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"import_ruamel",
"import_selective_context",
"import_httpx",
"import_openai",
]

import importlib.util
Expand Down Expand Up @@ -194,5 +195,10 @@ def import_ruamel():
def import_selective_context():
_check_library("selective_context")


def import_httpx():
_check_library("httpx")


def import_openai():
_check_library("openai")
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
openai
numpy
cachetools
requests
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def parse_requirements(file_name: str) -> List[str]:
setuptools.setup(
name="gptcache",
packages=find_packages(),
version="0.1.23",
version="0.1.24",
author="SimFG",
author_email="[email protected]",
description="GPTCache, a powerful caching library that can be used to speed up and lower the cost of chat "
Expand Down

0 comments on commit dd0f16f

Please sign in to comment.