Class ChatGPTTrait

The ChatGPT trait adds chatgpt resolver to the Query of the entities that its attached to.

Usage:

traits:
- type: chatgpt
  • In config.yml
chatgpt:
organisation: <OpenAI Organisation> Required
apiKey: <OpenAI API Key> Required
model: <OpenAI GPT-3 Model ID> Optional, defaults to davinci
maxTokens: <OpenAI API MaxTokens> Optional, defaults to 100
mock: <Boolean> Optional, defaults to false

Mermaid

ChatGPT Query

%%{init:{"theme":"dark"}}%% sequenceDiagram actor User participant Kosmos participant OpenAI User->>Kosmos: Query ChatGPT Kosmos->>OpenAI: Call OpenAI createCompletion activate OpenAI OpenAI->>Kosmos: Response deactivate OpenAI Kosmos->>User: Response
%%{init:{"theme":"default"}}%% sequenceDiagram actor User participant Kosmos participant OpenAI User->>Kosmos: Query ChatGPT Kosmos->>OpenAI: Call OpenAI createCompletion activate OpenAI OpenAI->>Kosmos: Response deactivate OpenAI Kosmos->>User: Response
sequenceDiagram
   actor User
   participant Kosmos
   participant OpenAI
   User->>Kosmos: Query ChatGPT
   Kosmos->>OpenAI: Call OpenAI createCompletion
   activate OpenAI
   OpenAI->>Kosmos: Response
   deactivate OpenAI
   Kosmos->>User: Response

Hierarchy

Constructors

Properties

Trait instance configuration.

_global: boolean = false

Whether this is a global (not bound to any specific schema item) trait instance.

_graphqlSchemaManager: GraphQLSchemaManager
_openai: any
_runtimeConfig: RuntimeConfig
_type?: "chatgpt"

Trait type.

dataSourceWrapper: DataSourceWrapper
graphqlSchemaManager: GraphQLSchemaManager

Methods

  • The chatGPT resolver is the function that is called when the chatgpt field is called. It calls the OpenAI API to get the response, using the input as the prompt. It then returns the response, first choice, first text.

    Returns

    The response from OpenAI.

    Parameters

    • datasourceWrapper: DataSourceWrapper

      Datasource wrapper object.

    • data: any

      The data object.

    Returns Promise<any>

  • This method is triggered when a trait callback has been activated

    Type Parameters

    • RT = any

    • Payload = any

    Parameters

    • callbackName: string

      This is the name of the callback function to call.

    • datasourceWrapper: DataSourceWrapper

      References to the Graph Hanlder

    • data: TraitDataObject<RT, Payload, Promise<any>>

      Request data passed along as part of the request.

    Returns Promise<RT>

Generated using TypeDoc