Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix python deps; update docs to include openai route #23

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions resources/py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ bash ./py-build.sh
- [LLMResponse](https://github.com/guardrails-ai/guardrails-api-client/tree/main/resources/py/docs/LLMResponse.md);
- [MetaData](https://github.com/guardrails-ai/guardrails-api-client/tree/main/resources/py/docs/MetaData.md);
- [ModelSchema](https://github.com/guardrails-ai/guardrails-api-client/tree/main/resources/py/docs/ModelSchema.md);
- [OpenAIChatCompletion](https://github.com/guardrails-ai/guardrails-api-client/tree/main/resources/py/docs/OpenAIChatCompletion.md);
- [OpenAIChatCompletionPayload](https://github.com/guardrails-ai/guardrails-api-client/tree/main/resources/py/docs/OpenAIChatCompletionPayload.md);
- [OpenAIChatCompletionPayloadMessagesInner](https://github.com/guardrails-ai/guardrails-api-client/tree/main/resources/py/docs/OpenAIChatCompletionPayloadMessagesInner.md);
- [OpenaiApi](https://github.com/guardrails-ai/guardrails-api-client/tree/main/resources/py/docs/OpenaiApi.md);
- [Outputs](https://github.com/guardrails-ai/guardrails-api-client/tree/main/resources/py/docs/Outputs.md);
- [OutputsParsedOutput](https://github.com/guardrails-ai/guardrails-api-client/tree/main/resources/py/docs/OutputsParsedOutput.md);
- [OutputsValidationResponse](https://github.com/guardrails-ai/guardrails-api-client/tree/main/resources/py/docs/OutputsValidationResponse.md);
Expand Down
32 changes: 32 additions & 0 deletions resources/py/docs/OpenAIChatCompletion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# OpenAIChatCompletion


## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **str** | The id |
**created** | **str** | The created date |
**model_name** | **str** | The model name |
**choices** | [**List[OpenAIChatCompletionPayloadMessagesInner]**](OpenAIChatCompletionPayloadMessagesInner.md) | |

## Example

```python
from guardrails_api_client.models.open_ai_chat_completion import OpenAIChatCompletion

# TODO update the JSON string below
json = "{}"
# create an instance of OpenAIChatCompletion from a JSON string
open_ai_chat_completion_instance = OpenAIChatCompletion.from_json(json)
# print the JSON string representation of the object
print(OpenAIChatCompletion.to_json())

# convert the object into a dict
open_ai_chat_completion_dict = open_ai_chat_completion_instance.to_dict()
# create an instance of OpenAIChatCompletion from a dict
open_ai_chat_completion_from_dict = OpenAIChatCompletion.from_dict(open_ai_chat_completion_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


32 changes: 32 additions & 0 deletions resources/py/docs/OpenAIChatCompletionPayload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# OpenAIChatCompletionPayload


## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**model** | **str** | The model to use for the completion | [optional]
**messages** | [**List[OpenAIChatCompletionPayloadMessagesInner]**](OpenAIChatCompletionPayloadMessagesInner.md) | The messages to use for the completion | [optional]
**max_tokens** | **int** | The maximum number of tokens to generate | [optional]
**temperature** | **float** | The sampling temperature | [optional]

## Example

```python
from guardrails_api_client.models.open_ai_chat_completion_payload import OpenAIChatCompletionPayload

# TODO update the JSON string below
json = "{}"
# create an instance of OpenAIChatCompletionPayload from a JSON string
open_ai_chat_completion_payload_instance = OpenAIChatCompletionPayload.from_json(json)
# print the JSON string representation of the object
print(OpenAIChatCompletionPayload.to_json())

# convert the object into a dict
open_ai_chat_completion_payload_dict = open_ai_chat_completion_payload_instance.to_dict()
# create an instance of OpenAIChatCompletionPayload from a dict
open_ai_chat_completion_payload_from_dict = OpenAIChatCompletionPayload.from_dict(open_ai_chat_completion_payload_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


30 changes: 30 additions & 0 deletions resources/py/docs/OpenAIChatCompletionPayloadMessagesInner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# OpenAIChatCompletionPayloadMessagesInner


## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**role** | **str** | The role of the message | [optional]
**content** | **str** | The content of the message | [optional]

## Example

```python
from guardrails_api_client.models.open_ai_chat_completion_payload_messages_inner import OpenAIChatCompletionPayloadMessagesInner

# TODO update the JSON string below
json = "{}"
# create an instance of OpenAIChatCompletionPayloadMessagesInner from a JSON string
open_ai_chat_completion_payload_messages_inner_instance = OpenAIChatCompletionPayloadMessagesInner.from_json(json)
# print the JSON string representation of the object
print(OpenAIChatCompletionPayloadMessagesInner.to_json())

# convert the object into a dict
open_ai_chat_completion_payload_messages_inner_dict = open_ai_chat_completion_payload_messages_inner_instance.to_dict()
# create an instance of OpenAIChatCompletionPayloadMessagesInner from a dict
open_ai_chat_completion_payload_messages_inner_from_dict = OpenAIChatCompletionPayloadMessagesInner.from_dict(open_ai_chat_completion_payload_messages_inner_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


96 changes: 96 additions & 0 deletions resources/py/docs/OpenaiApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# guardrails_api_client.OpenaiApi

All URIs are relative to *http://localhost*

Method | HTTP request | Description
------------- | ------------- | -------------
[**openai_chat_completion**](OpenaiApi.md#openai_chat_completion) | **POST** /guards/{guardName}/openai/v1/chat/completions | OpenAI SDK compatible endpoint for Chat Completions


# **openai_chat_completion**
> OpenAIChatCompletion openai_chat_completion(guard_name, open_ai_chat_completion_payload)

OpenAI SDK compatible endpoint for Chat Completions

### Example

* Api Key Authentication (ApiKeyAuth):
* Bearer (JWT) Authentication (BearerAuth):

```python
import guardrails_api_client
from guardrails_api_client.models.open_ai_chat_completion import OpenAIChatCompletion
from guardrails_api_client.models.open_ai_chat_completion_payload import OpenAIChatCompletionPayload
from guardrails_api_client.rest import ApiException
from pprint import pprint

# Defining the host is optional and defaults to http://localhost
# See configuration.py for a list of all supported configuration parameters.
configuration = guardrails_api_client.Configuration(
host = "http://localhost"
)

# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure API key authorization: ApiKeyAuth
configuration.api_key['ApiKeyAuth'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['ApiKeyAuth'] = 'Bearer'

# Configure Bearer authorization (JWT): BearerAuth
configuration = guardrails_api_client.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

# Enter a context with an instance of the API client
with guardrails_api_client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = guardrails_api_client.OpenaiApi(api_client)
guard_name = 'guard_name_example' # str | Guard name
open_ai_chat_completion_payload = guardrails_api_client.OpenAIChatCompletionPayload() # OpenAIChatCompletionPayload |

try:
# OpenAI SDK compatible endpoint for Chat Completions
api_response = api_instance.openai_chat_completion(guard_name, open_ai_chat_completion_payload)
print("The response of OpenaiApi->openai_chat_completion:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling OpenaiApi->openai_chat_completion: %s\n" % e)
```



### Parameters


Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**guard_name** | **str**| Guard name |
**open_ai_chat_completion_payload** | [**OpenAIChatCompletionPayload**](OpenAIChatCompletionPayload.md)| |

### Return type

[**OpenAIChatCompletion**](OpenAIChatCompletion.md)

### Authorization

[ApiKeyAuth](../README.md#ApiKeyAuth), [BearerAuth](../README.md#BearerAuth)

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json

### HTTP response details

| Status code | Description | Response headers |
|-------------|-------------|------------------|
**200** | The output of the completion | - |
**0** | Unexpected error | - |

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

5 changes: 4 additions & 1 deletion resources/py/pyproject.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ testpaths = [
]

[tool.pyright]
include = ["guardrails_api_client"]
include = ["guardrails_api_client"]

[tool.ruff.lint]
ignore = ["E721"]
10 changes: 5 additions & 5 deletions resources/py/scripts/prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ${
}

function updateDependencies () {
const pyProjectToml = fs.readFileSync(
let pyProjectToml = fs.readFileSync(
path.resolve('./pyproject.toml.template')
).toString();
const requirementsTxt = fs.readFileSync(
Expand All @@ -52,13 +52,13 @@ function updateDependencies () {
const dependencies = `dependencies = [
${
requirements
.map(r => `"${r.trim().split('\s').join('')}"`)
.join('\n')
.filter(r => r.length > 0)
.map(r => `\t"${r.trim().split('\s').join('')}"`)
.join(',\n')
}
]`;

pyProjectToml.replace('dependencies = []', dependencies)

pyProjectToml = pyProjectToml.replace('dependencies = []', dependencies)


fs.writeFileSync(
Expand Down
2 changes: 2 additions & 0 deletions resources/ts/docs/classes/BaseAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This is the base class for all generated API classes.

↳ [`GuardApi`](GuardApi.md)

↳ [`OpenaiApi`](OpenaiApi.md)

↳ [`ServiceHealthApi`](ServiceHealthApi.md)

↳ [`ValidateApi`](ValidateApi.md)
Expand Down
Loading