The Judini Python library provides convenient access to CodeGPT's Judini REST API from any Python 3.7+ application. The library includes type definitions for all requests parameters and response fields, and offers synchronous and asynchronous clients.
The API documentation can be found Here.
To install the package, simply run the following command:
pip install judini
- Create an account at https://app.codegpt.co
- Get your CodeGPT Api Key and Org ID from the Apikeys menu
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
AGENT_ID = "0000000-0000-0000-0000-000000000000"
messages = [{"role": "user", "content": "What is the meaning of life?"}]
# No streaming
chat = codegpt.chat_completion(agent_id=AGENT_ID,
messages=messages)
print(chat)
# Streaming
for chunk in codegpt.chat_completion(agent_id=AGENT_ID,
... messages=messages,
... stream=True):
print(chunk, end="")
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
codegpt.get_agents()
>> [Agent(id='0000000-0000-0000-0000-000000000000', ...),
>> Agent(id='0000000-0000-0000-0000-000000000001', ...)]
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
agent = codegpt.get_agent(agent_id='0000000-0000-0000-0000-000000000000')
agent
>> Agent(id='0000000-0000-0000-0000-000000000000',
>> name='Agent name', model='gpt-3.5-turbo',
>> prompt='You are a helpful assistant.',
>> welcome='Hello, how can I help you?',
>> ...)
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
codegpt.create_agent(name='Agent name', model='gpt-3.5-turbo',
... prompt='You are a helpful assistant.',
... welcome='Hello, how can I help you?')
>> Agent(id='0000000-0000-0000-0000-000000000000',
>> name='Agent name', model='gpt-3.5-turbo', ...)
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
codegpt.update_agent(agent_id='0000000-0000-0000-0000-000000000000',
... name='Agent name updated',
... model='gpt-4-turbo-preview')
>> Agent(id='0000000-0000-0000-0000-000000000000',
>> name='Agent name updated', model='gpt-3.5-turbo', ...)
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
codegpt.update_agent_documents(agent_id='0000000-0000-0000-0000-000000000000',
... document_ids=[DOCUMENT_ID_1, DOCUMENT_ID_2])
>> "Agent documents updated successfully"
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
codegpt.delete_agent('0000000-0000-0000-0000-000000000000')
>> "Agent deleted successfully"
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
codegpt.get_documents()
>> [Document(id='0000000-0000-0000-0000-000000000000', ...),
>> Document(id='0000000-0000-0000-0000-000000000001', ...)]
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
document = codegpt.get_document_by_id('0000000-0000-0000-0000-000000000000')
document
>> Document(id='0000000-0000-0000-0000-000000000000',
>> user_id='...',
>> name='My Document',
>> metadata='...',
>> content='Document content', ...)
Currently, only text documents are supported
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
codegpt.upload_document('path/to/file.txt', generate_metadata=False)
>> {'id': '0000000-0000-0000-0000-000000000000'}
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
codegpt.update_document_metadata(id='0000000-0000-0000-0000-000000000000',
... title='My Document Updated',)
>> "Document metadata updated successfully"
from judini import CodeGPTPlus
codegpt = CodeGPTPlus(api_key=CODEGPT_API_KEY, org_id=ORG_ID)
codegpt.delete_document('0000000-0000-0000-0000-000000000000')
>> "Document deleted successfully"
You can review more examples in our Cookbook Repository