Skip to content

Commit

Permalink
Merge pull request #4 from JudiniLabs/v2
Browse files Browse the repository at this point in the history
version 0.1.10
  • Loading branch information
Vokturz authored Feb 16, 2024
2 parents b83837c + 6a6f1c5 commit 9ee9e7d
Show file tree
Hide file tree
Showing 15 changed files with 817 additions and 496 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).



## [0.1.10] - 16-02-2024
### Changed
- Updated to new API version

## [0.0.24] - 12-20-2023

Expand Down
307 changes: 104 additions & 203 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,243 +12,144 @@ To install the package, simply run the following command:
pip install judini
```

## How to get API KEY and AGENT ID
## How to get your keys
1. Create an account at https://app.codegpt.co
2. Get your **CodeGPT Api Key** from the Api Keys menu
3. copy and replace your **CODEGPT API KEY**
4. Create an Agent and get your **AGENT ID**
5. Copy and replace your **AGENT KEY**

2. Get your **CodeGPT Api Key** and **Org ID** from the [Apikeys menu](https://app.codegpt.co/en/apikeys)

## How to Usage
### Import Judini SDK
```python
import os
from judini.codegpt.agent import Agent
from judini.codegpt.chat import Completion
from judini.codegpt.document import Document
import dotenv

# Load environment variables
dotenv.load_dotenv()

# CodeGPT Environment Variables API Key
CODEGPT_API_KEY = os.getenv("CODEGPT_API_KEY")
AGENT_ID = os.getenv("CODEGPT_AGENT_ID")
```
## How to use

### Chat Completion

```python
def chat_completion(agent_id, messages):
"""
Chat completion by Agent ID
Parameters:
agent_id (str): Agent ID
messages (dict): Messages [{ "role": "user", "content": "user prompt" }]
Returns:
Chat completion result
"""
completion = Completion(CODEGPT_API_KEY)
return completion.create(agent_id, messages)

# Example
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?"}]
chat = chat_completion(AGENT_ID, messages)

# No streaming
chat = codegpt.chat_completion(agent_id=AGENT_ID,
messages=messages)
print(chat)
```

### All Agent
```python
def getAllAgent():
"""
Retrieves a list of all available agents
Returns:
A list of agents.
"""
agent = Agent(CODEGPT_API_KEY)
return agent.getAll()
# Streaming
for chunk in codegpt.chat_completion(agent_id=AGENT_ID,
... messages=messages,
... stream=True):
print(chunk, end="")
```

# Example
my_agents = getAllAgent()
print(my_agents)
### Agents
#### List all agents
```python
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', ...)]
```

### Get agent data by ID
#### Get agent by ID
```python
def getAgentById(agent_id):
"""
Retrieves details of a specific agent by Agent ID
Parameters:
agent_id (str): Agent ID
Returns:
Agent details
"""
agent = Agent(CODEGPT_API_KEY)
return agent.getAgentById(agent_id)

# Example
AGENT_ID = os.getenv("CODEGPT_AGENT_ID")
my_agent = getAgentById(AGENT_ID)
print(my_agent)
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?',
>> ...)
```

### Update Agent
#### Create Agent
```python
def updateAgent(agent_id, data):
"""
Updates information for a specific agent.
Parameters:
agent_id (str): Agent ID
data (dict) : Agent data to update
Returns:
Updated agent details
"""
agent = Agent(CODEGPT_API_KEY)
return agent.update(agent_id, data)

# Example
AGENT_ID = os.getenv("CODEGPT_AGENT_ID")
new_data = {
'status': 'published',
'name': 'DevSuper2',
'documentId': [],
'description': 'Dev Super 2',
'prompt': 'You are an expert senior multilanguage programmer and you must help with the code and questions they ask of you.',
'topk': 100,
'temperature': 0.0,
'model': 'gpt-3.5-turbo',
'welcome': '',
'maxTokens': None,
}
update = updateAgent(AGENT_ID, new_data)
print (update)
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', ...)
```

### Link document to an agent
#### Update Agent info
```python
def linkDocument(agent_id, documentId):
"""
Links a document to a specific agent.
Parameters:
agent_id (str): Agent ID
documentId (str): Document ID to link.
Returns:
Response object indicating the result of the operation.
"""
agent = Agent(CODEGPT_API_KEY)
return agent.linkDocument(agent_id, documentId)

# Example
AGENT_ID = os.getenv("CODEGPT_AGENT_ID")
documentId = '123456' # replace with your document id
link_document = linkDocument(AGENT_ID, documentId)
print(link_document)
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', ...)
```

### Unlink document to an agent
#### Update Agent documents
```python
def unlinkDocument(agent_id, documentId):
"""
Unlinks a document from a specific agent.
Parameters:
agent_id (str): Agent ID to unlink the document from.
documentId (str): Document ID to unlink.
Returns:
Response object indicating the result of the operation.
"""
agent = Agent(CODEGPT_API_KEY)
return agent.unlinkDocument(agent_id, documentId)

# Example
AGENT_ID = os.getenv("CODEGPT_AGENT_ID")
documentId = '123456' # replace with your document id
unlink_document = unlinkDocument(AGENT_ID, documentId)
print(unlink_document)
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"
```

### Get All Document
#### Delete Agent
```python
def getAllDocument():
"""
Get all documents
Returns:
An object with all the account documents
"""
document = Document(CODEGPT_API_KEY)
return document.getAll()
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"
```

#example
my_documents = getAllDocument()
print(my_documents)
```

### Get Document by ID
### Documents
#### List all documents
```python
def getDocumentById(documentId):
"""
Get Document by ID
Returns:
A response object that contains the document data
"""
document = Document(CODEGPT_API_KEY)
return document.getDocumentById(documentId)

#example
documentId = 'YOUR_DOCUMENT_ID'
my_document = getDocumentById()
print(my_document)
```
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', ...)]
```

### Load Document
#### Get document by ID
```python
def loadDocument():
"""
Load document file.
Returns:
A response object containing the document's data.
"""
document = Document(CODEGPT_API_KEY)
return document.load()
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', ...)
```

#example
file = "example.txt" # path of your file
my_documents = loadDocument(file)
print(my_documents)
```
#### Upload a document
**Currently, only text documents are supported**
```python
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'}
```

### Training Document
#### Update document metadata
```python
def trainingDocument(documentId):
"""
Training document file.
Returns:
A response object containing the document's data.
"""
document = Document(CODEGPT_API_KEY)
return document.training(documentId)

#example
documentId = 'YOUR_DOCUMENT_ID'
document_to_training = trainingDocument(documentId)
print(document_to_training)
```
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"
```

### Load and Training Document
#### Delete a document
```python
def loadToTrainingDocument(file):
"""
Load and Training a Document
Returns:
A response object that contains the document data
"""
document = Document(CODEGPT_API_KEY)
return document.loadAndTraining(file)

#example
file = "example.txt" # path to your file
document = loadToTrainingDocument(file)
print(document)
```
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"
```

## MORE EXAMPLES
You can review more examples in our [Cookbook Repository](https://github.com/judinilabs/cookbook/)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
"wheel",
"pydantic"
]


Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = judini
version = 0.1.9
version = 0.1.10
author = Daniel Avila
author_email = daniel@judini.ai
description = CodeGPT python package
Expand All @@ -16,12 +16,13 @@ classifiers =
package_dir =
= src
packages = find:
python_requires = >=3.6
python_requires = >=3.7
install_requires =
requests
aiohttp
asyncio
python-dotenv
pydantic

[options.packages.find]
where = src
Expand Down
Loading

0 comments on commit 9ee9e7d

Please sign in to comment.