-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feature(wren-ui): add restful API #1585
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b7bf38e
rest api history repository
wwwy3y3 2b96fff
refactor
wwwy3y3 1884ae1
show intent reasoning
wwwy3y3 f8d2ede
add api history graphql api
wwwy3y3 f5dec5e
run sql
wwwy3y3 69e7a78
sanitize records
wwwy3y3 5a7d256
response id
wwwy3y3 129fd3b
return invalid_sql if it's provided
wwwy3y3 daee193
add language parameter to generate_sql
wwwy3y3 ec89807
add returnSqlDialect param to generate_sql
wwwy3y3 8d59e0a
stream explanation api
wwwy3y3 6b18484
generate_vega_spec api
wwwy3y3 bd53d7a
openapi yaml
wwwy3y3 9859664
fix graphql
wwwy3y3 cc461fc
vega utils
wwwy3y3 aa368be
upgrade uuid
wwwy3y3 bc97366
add fk to migration
wwwy3y3 0767658
add timeout
wwwy3y3 3ce476b
timeout error
wwwy3y3 fcc4280
fix created/updated time resolve null issue
wwwy3y3 1f7b37f
add required to pagination
wwwy3y3 d415504
fix code review issues
wwwy3y3 85c4928
fix language param default logics
wwwy3y3 8a940af
feat(wren-ui): API history page for monitoring RESTful API access (#1…
andreashimin c07f9aa
fix code review
wwwy3y3 0950762
typo
wwwy3y3 ae6106f
fix(wren-ui): defense mechanism for json string
andreashimin bf6d824
feat(wren-ui): adjust column width
andreashimin 33b9e0f
update openapi doc
wwwy3y3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * @param { import("knex").Knex } knex | ||
| * @returns { Promise<void> } | ||
| */ | ||
| exports.up = function (knex) { | ||
| return knex.schema.createTable('api_history', (table) => { | ||
| table.string('id').primary(); | ||
|
|
||
| // Project | ||
| table.integer('project_id').notNullable(); | ||
| table | ||
| .foreign('project_id') | ||
| .references('id') | ||
| .inTable('projects') | ||
| .onDelete('CASCADE'); | ||
|
|
||
| // Thread | ||
| table.string('thread_id'); | ||
|
|
||
| // API Type | ||
| table.string('api_type').notNullable(); | ||
|
|
||
| // Request | ||
| table.jsonb('headers'); | ||
| table.jsonb('request_payload'); | ||
|
|
||
| // Response | ||
| table.jsonb('response_payload'); | ||
|
|
||
| // Result | ||
| table.integer('status_code').notNullable(); | ||
| table.integer('duration_ms').notNullable(); | ||
| table.timestamps(true, true); | ||
| }); | ||
|
wwwy3y3 marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| /** | ||
| * @param { import("knex").Knex } knex | ||
| * @returns { Promise<void> } | ||
| */ | ||
| exports.down = function (knex) { | ||
| return knex.schema.dropTable('api_history'); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Wren AI API | ||
| description: API for interacting with Wren AI services | ||
| version: 1.0.0 | ||
| servers: | ||
| - url: /api/v1 | ||
| description: Wren AI API v1 | ||
| paths: | ||
| /generate_sql: | ||
| post: | ||
| summary: Generate SQL from natural language | ||
| description: Converts a natural language question into a SQL query | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| required: | ||
| - question | ||
| properties: | ||
| question: | ||
| type: string | ||
| description: The natural language question to convert to SQL | ||
| threadId: | ||
| type: string | ||
| description: Optional thread ID for conversation context | ||
| language: | ||
| type: string | ||
| description: Optional language override for the AI response (EN, ES, etc.) | ||
|
wwwy3y3 marked this conversation as resolved.
Outdated
|
||
| responses: | ||
| '200': | ||
| description: Successfully generated SQL | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| sql: | ||
| type: string | ||
| description: The generated SQL statement | ||
| threadId: | ||
| type: string | ||
| description: ID of the thread (existing or newly created) | ||
| '400': | ||
| description: Bad request or unable to generate SQL | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ErrorResponse' | ||
| '405': | ||
| description: Method not allowed | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ErrorResponse' | ||
| /run_sql: | ||
| post: | ||
| summary: Execute SQL and return results | ||
| description: Runs a SQL query and returns the results as structured data | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| required: | ||
| - sql | ||
| properties: | ||
| sql: | ||
| type: string | ||
| description: The SQL query to execute | ||
| threadId: | ||
| type: string | ||
| description: Optional thread ID for conversation context | ||
| limit: | ||
| type: integer | ||
| description: Maximum number of rows to return | ||
| default: 1000 | ||
| responses: | ||
| '200': | ||
| description: Successfully executed SQL | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| records: | ||
| type: array | ||
| description: Array of records, each represented as an object | ||
| items: | ||
| type: object | ||
| columns: | ||
| type: array | ||
| description: Metadata about the result columns | ||
| items: | ||
| $ref: '#/components/schemas/ColumnMetadata' | ||
| threadId: | ||
| type: string | ||
| description: ID of the thread (existing or newly created) | ||
| totalRows: | ||
| type: integer | ||
| description: The total number of rows returned | ||
| '400': | ||
| description: Bad request or SQL execution error | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ErrorResponse' | ||
| '405': | ||
| description: Method not allowed | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ErrorResponse' | ||
| /generate_vega_spec: | ||
| post: | ||
| summary: Generate Vega visualization spec | ||
| description: Generates a Vega specification for data visualization from a question and SQL query | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| required: | ||
| - question | ||
| - sql | ||
| properties: | ||
| question: | ||
| type: string | ||
| description: The natural language question about visualization | ||
| sql: | ||
| type: string | ||
| description: The SQL query that produces the data to visualize | ||
| threadId: | ||
| type: string | ||
| description: Optional thread ID for conversation context | ||
| sampleSize: | ||
| type: integer | ||
| description: Maximum number of rows to include in the visualization | ||
| default: 10000 | ||
| responses: | ||
| '200': | ||
| description: Successfully generated Vega specification | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| vegaSpec: | ||
| type: object | ||
| description: The Vega specification with embedded data | ||
| threadId: | ||
| type: string | ||
| description: ID of the thread (existing or newly created) | ||
| '400': | ||
| description: Bad request or specification generation error | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ErrorResponse' | ||
| '405': | ||
| description: Method not allowed | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ErrorResponse' | ||
| /stream_explanation: | ||
| get: | ||
| summary: Stream an explanation | ||
| description: Streams an explanation for a non-SQL query using server-sent events | ||
| parameters: | ||
| - name: queryId | ||
| in: query | ||
| description: The query ID to stream results from | ||
| required: true | ||
| schema: | ||
| type: string | ||
| responses: | ||
| '200': | ||
| description: Stream of explanation events | ||
| content: | ||
| text/event-stream: | ||
| schema: | ||
| type: string | ||
| description: Server-sent events stream with explanation chunks | ||
| '500': | ||
| description: Internal server error | ||
| components: | ||
|
wwwy3y3 marked this conversation as resolved.
|
||
| schemas: | ||
| ErrorResponse: | ||
| type: object | ||
| properties: | ||
| error: | ||
| type: string | ||
| description: Error message | ||
| code: | ||
| type: string | ||
| description: Error code | ||
| ColumnMetadata: | ||
| type: object | ||
| properties: | ||
| name: | ||
| type: string | ||
| description: Column name | ||
| type: | ||
| type: string | ||
| description: Data type of the column | ||
| notNull: | ||
| type: boolean | ||
| description: Whether the column allows null values | ||
| properties: | ||
| type: object | ||
| description: Additional column properties | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.