Fixed bugs and changes in Blog generation template and prompts. WIP.
This commit is contained in:
19
lib/gpt_providers/README.md
Normal file
19
lib/gpt_providers/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
gpt_providers are companies providing commercial/free GPT pre-trained models as saas.
|
||||
These include openai, Azure, Goodle, FB, Anthrophic etc
|
||||
|
||||
- If you want to use chatgpt and its models, then use openai as gpt_provider
|
||||
- We plan to integrate most the accurate, widely used models as gpt providers.
|
||||
- These will also include text to image and video generations as blogging artifacts.
|
||||
|
||||
gpt_provider=openai
|
||||
|
||||
------------------------------------
|
||||
|
||||
Here are some tips for using LLMs to generate ideas:
|
||||
|
||||
- Be as specific as possible in your prompts. The more specific you are, the better the LLM will
|
||||
be able to understand what you are asking for.
|
||||
- Use keywords in your prompts. This will help the LLM to generate ideas that are relevant to your topic.
|
||||
- Try different temperatures and top_p values. These parameters control the creativity and diversity of the generated ideas.
|
||||
- Experiment with different prompts and settings to see what works best for you.
|
||||
|
||||
57
lib/gpt_providers/openai_gpt_provider.py
Normal file
57
lib/gpt_providers/openai_gpt_provider.py
Normal file
@@ -0,0 +1,57 @@
|
||||
########################################################
|
||||
#
|
||||
# openai chatgpt integration for blog generation.
|
||||
# Choosing a model from openai and fine tuning its various paramters.
|
||||
#
|
||||
########################################################
|
||||
|
||||
from tqdm import tqdm, trange
|
||||
import openai
|
||||
import time # I wish
|
||||
|
||||
|
||||
def openai_chatgpt(prompt, model="text-davinci-003", temperature=0.5, max_tokens=2048, top_p=0.9, n=10):
|
||||
try:
|
||||
# Error in generating topic content: Rate limit reached for default-global-with-image-limits
|
||||
# in free account on requests per min. Limit: 3 / min. Please try again in 20s.
|
||||
for i in trange(21):
|
||||
time.sleep(1)
|
||||
# using OpenAI's Completion module that helps execute
|
||||
# any tasks involving text
|
||||
response = openai.Completion.create(
|
||||
# model name used here is text-davinci-003
|
||||
# there are many other models available under the
|
||||
# umbrella of GPT-3
|
||||
model="text-davinci-003",
|
||||
# passing the user input
|
||||
prompt=prompt,
|
||||
# generated output can have "max_tokens" number of tokens
|
||||
max_tokens=max_tokens,
|
||||
# number of outputs generated in one call
|
||||
n=n,
|
||||
top_p=top_p,
|
||||
#frequency_penalty=0,
|
||||
#presence_penalty=0
|
||||
)
|
||||
return(response)
|
||||
except openai.error.Timeout as e:
|
||||
#Handle timeout error, e.g. retry or log
|
||||
SystemError(f"OpenAI API request timed out: {e}")
|
||||
except openai.error.APIError as e:
|
||||
#Handle API error, e.g. retry or log
|
||||
SystemError(f"OpenAI API returned an API Error: {e}")
|
||||
except openai.error.APIConnectionError as e:
|
||||
#Handle connection error, e.g. check network or log
|
||||
SystemError(f"OpenAI API request failed to connect: {e}")
|
||||
except openai.error.InvalidRequestError as e:
|
||||
#Handle invalid request error, e.g. validate parameters or log
|
||||
SystemError(f"OpenAI API request was invalid: {e}")
|
||||
except openai.error.AuthenticationError as e:
|
||||
#Handle authentication error, e.g. check credentials or log
|
||||
SystemError(f"OpenAI API request was not authorized: {e}")
|
||||
except openai.error.PermissionError as e:
|
||||
#Handle permission error, e.g. check scope or log
|
||||
SystemError(f"OpenAI API request was not permitted: {e}")
|
||||
except openai.error.RateLimitError as e:
|
||||
#Handle rate limit error, e.g. wait or log
|
||||
SystemError(f"OpenAI API request exceeded rate limit: {e}")
|
||||
Reference in New Issue
Block a user