Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 80f67be

Browse files
committed
Added support for Continue generating feature
1 parent 09f3ef7 commit 80f67be

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

gpt4_openai/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class GPT4OpenAI(LLM):
1515
__file__ = __file__
1616
model: str = "gpt-4"
1717
plugin_ids: List[str] = []
18+
auto_continue: bool = False
1819

1920
@property
2021
def _llm_type(self) -> str:
@@ -25,10 +26,15 @@ def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
2526
if self.token is None:
2627
raise ValueError("You need to specify the token, please check https://github.com/Erol444/gpt4-openai-api#how-to-get-the-access-token")
2728

28-
self.chatbot = Chatbot({'access_token': self.token, 'model': self.model, 'plugin_ids': self.plugin_ids})
29+
self.chatbot = Chatbot({
30+
'access_token': self.token,
31+
'model': self.model,
32+
'plugin_ids': self.plugin_ids
33+
})
2934

3035
response = ""
31-
for data in self.chatbot.ask(prompt):
36+
for data in self.chatbot.ask(prompt=prompt,
37+
auto_continue=self.auto_continue):
3238
response = data["message"]
3339

3440
# Add to history

readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ Output will be:
8383
AI: Ahoy, me name be John an' I be likin' ta feast on some pizza, arr!
8484
```
8585

86+
## `Continue generating` support
87+
88+
In case of a large prompt answer, ChatGPT allows you to click `Continue generating` button. This library supports that as well.
89+
90+
```python
91+
llm = GPT4OpenAI(llm=my_token, model='gpt-4', auto_continue=True)
92+
very_long_response = llm(my_prompt)
93+
```
94+
8695
## How to get the access token
8796

8897
1. Go to https://chat.openai.com/api/auth/session

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="gpt4-openai-api",
10-
version="0.4.0",
10+
version="0.5.0",
1111
description="Python package for unofficial GPT-4 API access via chat.openai.com",
1212
long_description=long_description,
1313
long_description_content_type='text/markdown',

test/test_continue_generating.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
from dotenv import load_dotenv
3+
from gpt4_openai import GPT4OpenAI
4+
load_dotenv()
5+
6+
# accessToken from https://chat.openai.com/api/auth/session
7+
llm = GPT4OpenAI(token=os.environ["OPENAI_ACCESS_TOKEN"], model='gpt-4', auto_continue=True)
8+
9+
prompt = """
10+
Please write a detailed and comprehensive guide to developing a small business, starting from a business idea and
11+
going through all the necessary steps, such as writing a business plan, choosing a legal structure, obtaining financing,
12+
choosing a location, setting up your workspace, recruiting and hiring employees, developing products and services,
13+
marketing, sales, customer service, accounting and bookkeeping, reviewing business performance, and finally planning for
14+
growth and expansion. Be sure to include examples, tips, and potential pitfalls to watch out for along the way.
15+
"""
16+
response = llm(prompt)
17+
18+
# GPT4 should now return all 15 different steps of the business plan, one by one
19+
print(response)

0 commit comments

Comments
 (0)