Skip to content

ResponseType

Alfred Nutile edited this page May 31, 2023 · 8 revisions

Model

This ResponseType is a link in the Chain since many can be related to a project.

They get passed in a Project and a ResponseDto and return a ResponseDto

The output might be the final output to a "ChatUI" or an "Api"

For example it could go from "User Request in UI -> Embed Question Response Type -> Search Vectors Response Type -> Chat OpenAI RepsonseType (which streams the results)"

Generator

Simple way to get started is to run

php artisan larachain:response_type:create

Then you will be asked a few things

Name

Just the name of the ResponseType in my example it is a "StringReplacer"

Description

Let the person know what is does

Does it require settings

This will [COMING SOON] generate a update/edit route so you can then update the needed fields on the model.

The two fields are meta_data and prompt_token in my example my meta_data might look like this

{
  "search": [
    "foo",
    "bar"
  ],
  "replace": [
    "baz",
    "boo"
  ]
}

You can then make sure the generated Controller does the updates and validation and the generated Vuejs files will handle the UI

Types

VectorSearch

app/ResponseType/Types/VectorSearch.php This will take the Embedding in the Message model and search, it will return the results in the ResponseDto

EmbedQuestion

app/ResponseType/Types/EmbedQuestion.php This will take the Message model content and use that for make an embed out of it and save it back to embedding

CombineContent

app/ResponseType/Types/CombineContent.php This will take the ResponseDto content and iterate over it to shorten it for token usage. This is good to use after search results of VectorSearch

ChatUI

app/ResponseType/Types/ChatUi.php This will take the ResponseDto content and do a few things

  • See if there is a System message
    • If not it will make one with the prompt related to the ResponseType (see below PromptToken explained)
  • Create assistant message before and after if needed

ChatAPI

app/ResponseType/Types/ChatApi.php You can quickly create a Fortify based api endpoint for applications to talk to your data. You can see it in action here

PromptToken explained

We are using this library https://github.com/alnutile/larachain-prompt-templates

I will show how it is attached to the ResposeType form shortly