diff --git a/docs/mint.json b/docs/mint.json index d7299e830..b85eaf0e5 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -41,6 +41,10 @@ "name": "Views", "url": "views" }, + { + "name": "Prompts", + "url": "prompts" + }, { "name": "React", "url": "react" @@ -150,6 +154,38 @@ "queries/advanced/materialized-queries" ] }, + { + "group": "Basics", + "pages": [ + "prompts/basics/introduction", + "prompts/basics/model-configuration", + "prompts/basics/api-reference" + ] + }, + { + "group": "Logic", + "pages": [ + "prompts/logic/variables", + "prompts/logic/parameters", + "prompts/logic/if-else", + "prompts/logic/loops" + ] + }, + { + "group": "Advanced", + "pages": [ + "prompts/advanced/config", + "prompts/advanced/run-query", + "prompts/advanced/reference-prompts", + "prompts/advanced/cast-methods" + ] + }, + { + "group": "Models", + "pages": [ + "prompts/models/openai" + ] + }, { "group": "Basics", "pages": [ diff --git a/docs/prompts/advanced/cast-methods.mdx b/docs/prompts/advanced/cast-methods.mdx new file mode 100644 index 000000000..54213bd44 --- /dev/null +++ b/docs/prompts/advanced/cast-methods.mdx @@ -0,0 +1,49 @@ +--- +title: 'Cast Methods' +description: 'Converts data types in Latitude logic blocks, ensuring that SQL operations are performed with the correct data type.' +--- + +## Introduction + +The `cast` method allows you to convert values to a different type in your prompt logic enclosed in `{ }`. Cast ensures that the data types of variables are suitable for the operations you wish to perform. + +## Example + +Consider a scenario where you have a parameter named `limit`, but the user has provided a value as a string, `"3"`, instead of a numeric value. To correctly perform a comparison operation, you need the value to be of a numeric type. + +Without casting, the comparison in the following block would not work as expected: + +``` +{#if limit > 5} + ... +{:else} + ... +{/if} +``` + + +This is because, with `limit = "3"`, you're comparing the string `"3"` to the number `5`, which leads to an incorrect comparison. + +### Solution: Using `cast` + +To resolve this, you can use the `cast` function to convert `limit` to an integer: + +``` +{#if cast(limit, "int") > 5} + ... +{:else} + ... +{/if} +``` + +This way, if `limit` is `"3"`, it gets converted to the numeric value `3` before the comparison, ensuring the operation is correctly performed. + +## Accepted Casting Types + +You can cast values to various types using the `cast` method. The following are the accepted types for casting: + +- `string` or `text`: Converts the value to a string. Both `string` and `text` perform the same function. +- `int`: Converts the value to an integer. +- `float` or `number`: Converts the value to a floating-point number. Both `float` and `number` are treated similarly. +- `bool` or `boolean`: Converts the value to a boolean. Both `bool` and `boolean` are interchangeable and perform the same function. +- `date`: Converts the value to a date. \ No newline at end of file diff --git a/docs/prompts/advanced/config.mdx b/docs/prompts/advanced/config.mdx new file mode 100644 index 000000000..328891b96 --- /dev/null +++ b/docs/prompts/advanced/config.mdx @@ -0,0 +1,30 @@ +--- +title: 'Prompt configuration' +description: 'Configure how your Language Model generates each prompt' +--- +import PromptConfigDocs from '/snippets/prompts/config.mdx' + +In addition to your own source's behaviour, you can configure how Latitude will handle the data in each specific query. This can be done by adding a `config` tag to the query itself. +This keyword will not be included in the query that gets sent to your source, but it defines how Latitude will handle the data. + +## Syntax + +A `config` tag is defined as a key-value object in the query. Here's an example: +```sql +{@config model = 'gpt-3.5-turbo'} /* Sets the model to use */ +{@config json = true} /* Sets the response to be a JSON object */ + +Create a JSON object with a list of users and their corresponding emails. +``` + + + Any `@config` value must be defined using a literal value, without any variables or expressions. Using variables or expressions will result in a syntax error. + + +## Default configuration + +If you want to set a default configuration for all the prompts in a model, you can do so by adding a `config` object in the model schema. Go to [Model configuration](/prompts/basics/model-configuration) to learn more about the configuration file. + +## Available options + + diff --git a/docs/prompts/advanced/reference-prompts.mdx b/docs/prompts/advanced/reference-prompts.mdx new file mode 100644 index 000000000..9863ca753 --- /dev/null +++ b/docs/prompts/advanced/reference-prompts.mdx @@ -0,0 +1,41 @@ +--- +title: 'Reference other prompts' +description: 'Learn how to include code from another prompt' +--- + +## Introduction + +The Reference Prompts feature allows you to include code from another file in your current prompt. This is useful for reusing common parts of a prompt, ensuring that your instructions are consistent and easy to maintain. + +## How It Works + +To reference code from another prompt, use the syntax `{ref ('other_prompt')}`, where `other_prompt` is the name of another `.prompt` file located in the `/prompts` folder. This syntax compiles the specified prompt and imports the instructions to the location where it is added. + +### Referencing prompts as a source + +An important use case for referencing other prompts is creating specific instructions for multiple prompts. You can do this as follows: + +```jsx prompts/data/data_engineer_description.prompt +You are a data engineer, an expert on data analysis and visualization. +``` + +```jsx prompts/data/analysis.prompt +{ref('./data_engineer_description')} + +Describe the results of the following table: +{table(runQuery('data'))} +``` + +Which will translate to: + +```md prompts/data/analysis.prompt +You are a data engineer, an expert on data analysis and visualization. + +Describe the results of the following table: + +| id | name | age | city | +|----|------|-----|------| +| 1 | John | 25 | New York | +| 2 | Jane | 30 | Los Angeles | +| 3 | Bob | 35 | Chicago | +``` diff --git a/docs/prompts/advanced/run-query.mdx b/docs/prompts/advanced/run-query.mdx new file mode 100644 index 000000000..8c88f3fdc --- /dev/null +++ b/docs/prompts/advanced/run-query.mdx @@ -0,0 +1,70 @@ +--- +title: 'Run Query' +description: 'Analyze the results of a query and generate instructions based on the results.' +--- + +## Introduction + +The `runQuery` function allows you to dynamically create instructions based on the results from a query. This functionality is particularly useful when you need to analyze data, or generate different instructions based on a value from your database. + +## Syntax + +The `runQuery` function must take a string as an argument, which represents the path to the query file. + +Additionally, you can pass a JSON object as a second argument to the function, to specify the parameters required by the query. + +```jsx +{ user_id = param('user_id') } +{ results = runQuery('user_actions', { user_id: user_id }) } +``` + +The returned value will always be an array of objects, where each object represents a row in the query result, and the keys of the object represent the column names. + +```json +[ + { + "id": 302, + "user_id": 1, + "action": "signup", + "date": "2023-01-01" + }, + { + "id": 527, + "user_id": 1, + "action": "purchase", + "date": "2023-01-02" + }, + { + "id": 1091, + "user_id": 2, + "action": "purchase", + "date": "2023-01-03" + } +] +``` + +## Interpolating to the prompt + +Depending on your needs, you may want to print the results to the resulting prompt in a specific format. To do this, you can simply use the table, json or csv functions to automatically format the results. + +However, if you want to print them in a different format, you will need to iterate over the results and print them manually. Read more about [Loops](/prompts/logic/loops) to learn how to do this. + + + ```jsx Raw prompt + {user_id = param('user_id')} + {results = runQuery('user_actions', { user_id: user_id })} + + Based on the following actions from user {user_id}, generate a report: + + {#each results as row} + - {row.date}: {row.action} + {/each} + ``` + ```md Compiled prompt + Based on the following actions from user 1, generate a report: + + - 2023-01-01: signup + - 2023-01-02: purchase + - 2023-01-03: purchase + ``` + diff --git a/docs/prompts/basics/api-reference.mdx b/docs/prompts/basics/api-reference.mdx new file mode 100644 index 000000000..9dc526847 --- /dev/null +++ b/docs/prompts/basics/api-reference.mdx @@ -0,0 +1,34 @@ +--- +title: 'API Reference' +description: 'How your prompt endpoints are exposed' +--- + +## Introduction + +For each of your prompts, Latitude automatially generates a REST API at `/api/prompt/`. + +Accessing to this endpoint will return as a plain text the response of your prompt. + +## Parameters + +In your prompt, you can use dynamic parameters, like it is explained in the [Parameters Section](/prompts/logic/parameters). To pass these parameters to your API, you can simply add them as query parameters in the URL. + +For example, if you have a prompt named `joke` with the following content: + +```prompt +Tell me a joke about { param('topic') } +``` + +You can access to this prompt at `/api/prompt/joke?topic=cats` and it will return a joke about cats. + +## Streaming + +If you want to stream the response of your prompt instead of waiting for it to be generated, you can add the internal `__stream` parameter to your URL and set it to `true`. This will make Latitude return a [SSE stream](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) instead of a plain text response. + +For example, if you have a prompt named `joke` with the following content: + +```prompt +Tell me a joke about { param('topic') } +``` + +You can access to this prompt at `/api/prompt/joke?topic=cats&__stream=true` and it will return a SSE stream of the response of your prompt. diff --git a/docs/prompts/basics/introduction.mdx b/docs/prompts/basics/introduction.mdx new file mode 100644 index 000000000..01a22963e --- /dev/null +++ b/docs/prompts/basics/introduction.mdx @@ -0,0 +1,71 @@ +--- +title: 'Introduction' +description: 'Learn the basics on how to prompt your data' +--- + +## Introduction + +Latitude Prompts is a powerful tool that allows you to easily generate AI insights from your data. It is a versatile tool that can be used for a variety of purposes, such as data analysis, data visualization, and data augmentation. + +Similar to how Latitude Queries work, Prompts are automatically exposed as endpoints to your Latitude API! This means that you can use them in your frontend, in your backend, or even in your database. Also, thanks to our dynamic engine, you can easily integrate your data and even user inputs into your prompts. + +## Setup + +To use Latitude Prompts, just follow these steps: + + + + [Use the CLI](/guides/examples/basic-example#1-create-a-new-data-app) to create a new project. + + + Add a folder called `prompts` to your project's root. This is where you will store your prompts. + + + Create a `.yaml` file with your Model configuration. This file will let Latitude know how to connect to your Language Model and how to generate responses. + + Read [Model Configuration](/prompts/basics/model-configuration) to learn more about how to configure your model. + + + Inside the `prompts` folder, create a `.prompt` file with your prompt. + + + +## Prompt syntax + +Regular prompts are written in plain text. Just write your prompt as you would write it in a regular text editor, and your Language Model will generate a response based on the prompt. + +However, you can also use special syntax to make your prompts more powerful and dynamic. This syntax allows you to reference data from your database, pass parameters to your Language Model, and more. + +Read more about the prompt syntax in the [Logic Section](/prompts/logic/variables) section. + +## Run your prompt + +Once you have configured your model and prompt, you can run your prompt by using the CLI or the API. + +### CLI + +To run your prompt using the CLI, use the `prompt` command: + +```bash +latitude prompt +``` + +This will run your prompt and print the response to the console as it is generated. The prompt name is defined by the relative path of the `.prompt` file from the `prompts` folder. + +To add parameters from the CLI, use the `--param` flag. You can add it multiple times to pass multiple parameters. + +```bash +latitude prompt table_insights --param limit=10 --param user_name="John Doe" +```` + +For debugging purposes, you can use the `--debug` flag to print the final prompt that will be sent to your Language Model. This can be useful for debugging and understanding how your prompt is being generated. + +```bash +latitude prompt table_insights --debug +``` + +### API + +You can also run your prompt using the API. To do this, you can use the `/api/prompt/` endpoint. + +Read more about the API in the [API Reference](/prompts/basics/api-reference) section. diff --git a/docs/prompts/basics/model-configuration.mdx b/docs/prompts/basics/model-configuration.mdx new file mode 100644 index 000000000..043155e4d --- /dev/null +++ b/docs/prompts/basics/model-configuration.mdx @@ -0,0 +1,42 @@ +--- +title: 'Model Configuration' +description: 'Learn how to configure your language model' +--- +import PromptConfigDocs from '/snippets/prompts/config.mdx' + +## Introduction + +Language Models are the engines that generate responses from your prompts. You can configure your Language Model by creating a `.yaml` file in your project's `prompts` folder. + +## Structure + +You can configure multiple Language Models in your project, each with their own configuration. To do this, you can create multiple `.yaml` in different subfolders. Prompts will automatically use the configuration file closest to the prompt file. + + + You can not add two Model configuration files in the same folder. + + +## Configuration + +The configuration file is a YAML file that contains the following fields: + +- `type`: The type of your Language Model. Check out the [Models Section](/prompts/models/openai) to learn more about the available models. +- `details`: Configuration details for your Language Model. This field is specific to each type of Language Model. +- `config`: A configuration object that defines how your Language Models will generate responses. Although all model types have the same properties, each type will have different default values. + +### Config options + +The `config` field can contain any of the following properties: + + + +#### Example: + +```yaml +type: openai +config: + model: gpt-3.5-turbo + temperature: 0.2 # Lower temperature values are better if consistency is important + json: true +``` + diff --git a/docs/prompts/logic/if-else.mdx b/docs/prompts/logic/if-else.mdx new file mode 100644 index 000000000..9620e7c14 --- /dev/null +++ b/docs/prompts/logic/if-else.mdx @@ -0,0 +1,124 @@ +--- +title: 'Conditions' +description: 'Adjust your prompts dynamically according to conditions' +--- + +## Introduction + +The logic blocks supports conditional execution through the use of if and else, allowing dynamic prompt indications to be executed only when certain conditions are met. + +## Syntax + +The syntax of these conditions is as follows: + +### Simple Conditions +Includes the code only if the condition is true, without an alternative. + +```jsx +{#if param('use_detailed_answer')} + Please provide a detailed answer, including all the steps and explanations. +{/if} +``` + +### Conditions with Else +Allow two content alternatives. If the condition is not true, the content defined after `{:else}` will be included. + +```jsx +{#if param('use_detailed_answer')} + Please provide a detailed answer, including all the steps and explanations. +{:else} + Please provide a concise answer, without getting into the details. +{/if} +``` + +### Multiple Conditions +Allow unlimited content alternatives. It evaluates conditions cascading until one is met. If none is met, it returns the content defined after `{:else}`. + +```jsx +{#if param('answer_type') == 'detailed'} + Please provide a detailed answer, including all the steps and explanations. +{:else if param('answer_type') == 'steps'} + Provide your answer as a list of simple steps. +{:else if param('answer_type') == 'concise'} + Please provide a concise explanation about your answer, without getting into the details. +{:else} + Just provide a brief answer, without any explanations. +{/if} +``` + +## Expressions + +Expressions are crucial for determining the logic within if and else constructs. They can evaluate variables, constants, or any combination of the two using a variety of operators. + +### Values + +Values can be inside expressions: + +- **Prompt parameters**: Values passed to the request. For example, `param('response_type')` could be a query parameter representing how the user wants the response to look like. Check out [Prompt Parameters](/prompts/logic/parameters) for more information. + ```jsx + {#if param('response_type') == 'detailed'} + ``` +- **Variables/Parameters**: Variables can be defined in the prompt itself to be used in expressions. For example, `id` could be a variable representing a user's ID. Check out [Variables](/prompts/logic/variables) for more information. + ```jsx + {id = param('user_id')} + {max_id = 100} + + {#if id > max_id} + /* Your custom prompt here */ + {/if} + ``` + +### Operations + +Complex operations can be performed within expressions: + +- **Arithmetic Operations**: Basic arithmetic operations can be performed within expressions. + ```jsx + {#if param('limit') * 2 > 100} + ``` + +- **String Operations**: String operations can be performed within expressions. + ```jsx + {#if param('username').length > 5} + {#if param('username').startsWith('vip-')} + ``` + +### Comparisons + +Expressions are compared with operators, which include the following options: + +- **Equality and Inequality**: + - `==`: Equal to + ```jsx + {#if id == 100} + ``` + - `!=`: Not equal to + ```jsx + {#if id != 100} + ``` +- **Greater Than or Less Than**: + - `>`: Greater than + ```jsx + {#if id > 100} + ``` + - `<`: Less than + ```jsx + {#if id < 100} + ``` + - `<=`: Less than or equal to + ```jsx + {#if id <= 100} + ``` + - `>=`: Greater than or equal to + ```jsx + {#if id >= 100} + ``` +- **Multiple conditions**: + - `&&`: Logical AND to concatenate multiple conditions in the same expression. **They must all be true to continue**. + ```jsx + {#if id > 100 && workspace_id = 45} + ``` + - `||`: Logical OR to concatenate multiple conditions in the same expression. **At least one of them must be true to continue**. + ```jsx + {#if id > 100 || workspace_id = 45} + ``` \ No newline at end of file diff --git a/docs/prompts/logic/loops.mdx b/docs/prompts/logic/loops.mdx new file mode 100644 index 000000000..5379ecb01 --- /dev/null +++ b/docs/prompts/logic/loops.mdx @@ -0,0 +1,126 @@ +--- +title: 'Loops' +description: 'Learn how to use loops to repeat prompt indications from a list of elements.' + +--- + +## Introduction + +Loops allow you to add a prompt indication for each item in a collection. + +## Syntax + +The syntax for a loop is defined by three main components: +```jsx +{#each collection as item, index} + /* prompt */ +{/each} +``` + - **Collection**: An iterable object that contains the items to be looped over. This can be a manual array, an expression, or an existing variable. + - **Item**: The current element in the collection for this iteration. This will define a new variable only available within the loop. + - **Index** (optional): The current index of the item in the collection, starting by 0. As with the item, this will define a new variable only available within the loop. + +Let's see an example of how it works: + +```jsx Your Prompt +For each of the following items, describe its importance: +{#each ["trust", "integrity", "communication", "teamwork", "innovation"] as value, i} + {i+1}. {value} +{/each} +``` +``` Compiled Prompt +For each of the following items, describe its importance: +1. trust +2. integrity +3. communication +4. teamwork +5. innovation +``` + + +You can also add an `{:else}` block after the loop, which would be executed if the collection is empty: + +```jsx +{#each collection as item, index} + /* prompt for each item */ +{:else} + /* prompt if there are no items */ +{/each} +``` + +## Use cases + +### Avoiding repetitive prompts + +Now, consider the scenario where you need to ask about feedback on different aspects such as service, product quality, and user experience. The prompts would look like this: + +```md +Please provide your feedback on the following aspects: +1. Service +2. Product Quality +3. User Experience +``` + +Instead of writing repetitive code, you can use a loop to iterate over the aspects and generate the prompts dynamically: + + +```jsx Your Prompt +{aspects = ["Service", "Product Quality", "User Experience"]} + +Please provide your feedback on the following aspects: +{#each aspects as aspect, i} + {i+1}. {aspect} +{/each} +``` +```md Compiled Prompt +Please provide your feedback on the following aspects: +1. Service +2. Product Quality +3. User Experience +``` + + +### Iterating over other query results + +You can also use loops to iterate over the results from a query. For example, if you have a list of tasks and you want to ask for their status, you can use a loop to iterate over the task IDs: + + +```jsx Your Prompt +{tasks = runQuery('tasks')} + +Please provide the status of the following tasks: +{#each tasks as task, i} + {#if i > 0} , {/if} /* Add a comma before each item except the first one */ + Task {task.id}: {task.name} +{/each} +``` +```md Compiled Prompt +Please provide the status of the following tasks: +Task 1: Design Phase, Task 2: Development Phase, Task 3: Testing Phase +``` + + +### Iterating params for a prompt + +Imagine you have a multi-select option in your application that allows selecting multiple values. You can pass the selected values as an array to the prompt param and iterate over it to include each selected value in the prompt. + +In this case, we pass `selected_topics` that can be some of these `['AI', 'Machine Learning', 'Data Science']` + + +```jsx Your Prompt +Please provide a summary for each of the selected topics: +{selectedTopics = param('selected_topics', [])} + +{#if selectedTopics.length > 0} + {#each selectedTopics as topic, index} + - {topic} + {/each} +{/if} +``` +```md Compiled Prompt +Please provide a summary for each of the selected topics: +- AI +- Machine Learning +- Data Science +``` + diff --git a/docs/prompts/logic/parameters.mdx b/docs/prompts/logic/parameters.mdx new file mode 100644 index 000000000..bd1119e50 --- /dev/null +++ b/docs/prompts/logic/parameters.mdx @@ -0,0 +1,38 @@ +--- +title: 'Parameters' +description: 'Dynamic parameters in AI prompts' +--- + +## Introduction +In some cases, we want to generate prompts based on some dynamic input. This allows for more flexibility in the responses we generate and how we display them. + +This can be done with the help of parameters, which are passed to the prompt when it is executed. + +## Parameters +The parameters are values that are passed to the prompt when it is executed, either through [View components](/views/basics/running-prompts#parameters), [API requests](/guides/examples/api#4-1-passing-parameters-to-your-prompts), or [using the CLI](/guides/development/latitude-cli#passing-parameters). To know more information about how parameters are used in each case, please refer to their own documentation. + +In the prompt, the parameters can be used with the `param()` function. This function retrieves the value specified by the user and inserts it safely into the prompt. + +```jsx +{param('greeting')}, how can I assist you today? +``` + +### Fallback + +If the required parameter is not found in the request, the prompt will fail. To avoid this, you can set a fallback value in the `param()` function. + +```jsx +{param('greeting', 'Hello')}, how can I assist you today? +/* If no greeting is found, it will use 'Hello' as the value */ +``` + +### Check if a parameter is present + +Requesting a parameter that is not present will result in an error. To avoid this, you can check if the parameter is present using a [conditional statement](/prompts/logic/if-else) and `false` as the fallback value. + +```jsx +{#if param('user_id', false)} + /* The parameter is present in the request */ + Welcome back, user {param('user_id')}! +{/if} +``` diff --git a/docs/prompts/logic/variables.mdx b/docs/prompts/logic/variables.mdx new file mode 100644 index 000000000..35e06c8a2 --- /dev/null +++ b/docs/prompts/logic/variables.mdx @@ -0,0 +1,112 @@ +--- +title: 'Variables' +description: 'Modify and optimize prompt generation with the flexibility of variables' +--- + +## Introduction + +Variables and constants store values you can later use anywhere in your prompt. + +## Basic Usage +Variables are placeholders that can be assigned and reassigned values throughout the prompt. + +To assign a value to a variable, use the equal sign `=` followed by the value. +```jsx +{name = 'foo'} +{age = 30} +{sum = 2 + 4} +``` + +For example, take a look at the following prompt definition and what will actually be generated: + +```jsx Your Prompt +/* Defining the variable and prompt */ +{sum = 2 + 4} + +Generate a list of {sum} names. +``` + +```md Compiled Prompt +Generate a list of 6 names. +``` + + +### Incrementing +Variables can be modified using operations such as addition. + + +```jsx Your Prompt +{counter = 10} /* Define the variable */ + +List the following values: +{#each [1, 2, 3] as item, index} + Value {counter} + + /* Add a comma at the end to every element except the last one */ + {#if index + 1 < item.length} + , + {/if} + + /* Increment the value of the variable */ + {counter = counter + 10} +{/each} +``` +```md Compiled Prompt +Please list the following values: +Value 10, Value 20, Value 30 +``` + + +## Constants +Constants are similar to variables but, once defined, their value cannot be changed. Also, the main syntax difference is constants are defined using the `@const` keyword. + +```jsx +{@const greeting = 'Hello.'} +``` + + +```jsx Your Prompt +{@const greeting = 'Hello.'} /* Defined a constant */ + +{#if param('tone') == 'informal'} + {greeting = 'Hi!'} /* Attempting to reassign the constant */ +{/if} +``` +```md Compiled Prompt +'!Error: Cannot reassign a constant' +``` + + +## Scope +### Global +Variables defined outside of any logic blocks are considered global and can be modified and accessed throughout the entire code. +```jsx +{greeting = 'Hello.'} +``` + +Variables can be accessed and modified anywhere in the code. + +```jsx Your Prompt +{greeting = 'Hello.'} /* Define the variable */ + +{greeting} It is a beautiful day. + +{greeting = 'Hi!'} /* Reassign the variable */ + +{greeting} How are you doing? +``` +```md Compiled Prompt +Hello. It is a beautiful day. +Hi! How are you doing? +``` + + +### Local Variables +Variables defined within logic blocks are local to that block. They cannot be accessed outside the block in which they are defined. + +```jsx +{greeting = 'Hello.'} +{#if condition} + {goodbye = 'Goodbye.'} /* Accessible only within this block */ +{/if} +``` diff --git a/docs/prompts/models/openai.mdx b/docs/prompts/models/openai.mdx new file mode 100644 index 000000000..e4fb1b7a5 --- /dev/null +++ b/docs/prompts/models/openai.mdx @@ -0,0 +1,32 @@ +--- +title: 'OpenAI' +description: 'Configure your OpenAI language model' +--- + +## Details + +In order to use Latitude with OpenAI, you will need the following information: + + + Your OpenAI API key. You can find it in your [OpenAI dashboard](https://platform.openai.com/account/api-keys). + + +```yaml prompts/openai/source.yaml +type: openai +details: + apiKey: sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +``` + + + Instead of using your API key directly, we recommend using environment variables to store your secrets. Read more about [environment variables](/guides/development/environment-variables) to learn how to do this. + + +## Default configuration + +By default, openai prompts will use the following configuration: + - **model**: gpt-4o + - **temperature**: 0.1 + - **top_p**: 1 + - **json**: false + +To learn more about the configuration options, read the [model configuration section](/prompts/basics/model-configuration#config-options). \ No newline at end of file diff --git a/docs/prompts/models/test.mdx b/docs/prompts/models/test.mdx new file mode 100644 index 000000000..1f43cf219 --- /dev/null +++ b/docs/prompts/models/test.mdx @@ -0,0 +1,22 @@ +--- +title: 'Test' +description: 'A test model for debugging purposes' +--- + +The Test model is a simple model that can be used for debugging purposes. It will always return the contents from the prompt, instead of actually generating a response. + +Just add "test" as the model type in your `.yaml` file: + +```yaml prompts/test/source.yaml +type: test +``` + +## Propmts + +Creating a propmt with simple text will just return the same text as the response. + +Additionally, you can use custom commands to make the model behave differently. To do so, create a new line in your prompt with the following format: + + - `FAIL `: Will always fail with the specified message. + - `SLEEP `: Will wait for the specified number of milliseconds before contining generating the response. + diff --git a/docs/snippets/prompts/config.mdx b/docs/snippets/prompts/config.mdx new file mode 100644 index 000000000..df063d6a8 --- /dev/null +++ b/docs/snippets/prompts/config.mdx @@ -0,0 +1,25 @@ + + The name of the Language Model. This name must be available from the used model type, or it will fail otherwise. + + + + A number between 0 and 1 that controls the randomness of the generated response. A higher value will make the response more random, while a lower value will make it more deterministic. + + + + An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + + + + A number that controls the randomness of the generated response. If the rest of the config does not change, same seeds will **always** generate the same response. + + If not specified, the response will always be random. + + + + If set to true, the response will be garanteed to be a valid JSON object. + + + Even if this is set to true, you still need to specify that the response must be a JSON object in the prompt itself. + + \ No newline at end of file