This guide is for developers looking to contribute to Foyle.
This is the multi-page printable view of this section. Click here to print.
Developer Guide
1 - Documentation Guidelines
We use Hugo to format and generate our website, the Docsy theme for styling and site structure, and Netlify to manage the deployment of the site. Hugo is an open-source static site generator that provides us with templates, content organisation in a standard directory structure, and a website generation engine. You write the pages in Markdown (or HTML if you want), and Hugo wraps them up into a website.
All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult GitHub Help for more information on using pull requests.
Quick start with Netlify
Here’s a quick guide to updating the docs. It assumes you’re familiar with the GitHub workflow and you’re happy to use the automated preview of your doc updates:
- Fork the Foyle repo on GitHub.
- Make your changes and send a pull request (PR).
- If you’re not yet ready for a review, add “WIP” to the PR name to indicate it’s a work in progress. (Don’t add the Hugo property “draft = true” to the page front matter, because that prevents the auto-deployment of the content preview described in the next point.)
- Wait for the automated PR workflow to do some checks. When it’s ready, you should see a comment like this: deploy/netlify — Deploy preview ready!
- Click Details to the right of “Deploy preview ready” to see a preview of your updates.
- Continue updating your doc and pushing your changes until you’re happy with the content.
- When you’re ready for a review, add a comment to the PR, and remove any “WIP” markers.
Updating a single page
If you’ve just spotted something you’d like to change while using the docs, we have a shortcut for you:
- Click Edit this page in the top right hand corner of the page.
- If you don’t already have an up to date fork of the project repo, you are prompted to get one - click Fork this repository and propose changes or Update your Fork to get an up to date version of the project to edit. The appropriate page in your fork is displayed in edit mode.
- Follow the rest of the Quick start with Netlify process above to make, preview, and propose your changes.
Previewing your changes locally
If you want to run your own local Hugo server to preview your changes as you work:
Follow the instructions in Getting started to install Hugo and any other tools you need. You’ll need at least Hugo version 0.45 (we recommend using the most recent available version), and it must be the extended version, which supports SCSS.
Fork the Foyle repo repo into your own project, then create a local copy using
git clone
. Don’t forget to use--recurse-submodules
or you won’t pull down some of the code you need to generate a working site.git clone --recurse-submodules --depth 1 https://github.com/jlewi/foyle.git
Run
hugo server
in the site root directory. By default your site will be available at http://localhost:1313/. Now that you’re serving your site locally, Hugo will watch for changes to the content and automatically refresh your site.Continue with the usual GitHub workflow to edit files, commit them, push the changes up to your fork, and create a pull request.
Creating an issue
If you’ve found a problem in the docs, but you’re not sure how to fix it yourself, please create an issue in the Foyle repo. You can also create an issue about a specific page by clicking the Create Issue button in the top right hand corner of the page.
Useful resources
- Docsy user guide: All about Docsy, including how it manages navigation, look and feel, and multi-language support.
- Hugo documentation: Comprehensive reference for Hugo.
- Github Hello World!: A basic introduction to GitHub concepts and workflow.
2 - Evaluation
What You’ll Learn
- How to setup and run experiments to evaluate the quality of the AI responses in Foyle
Produce an evaluation dataset
In order to evaluate Foyle you need a dataset of examples that consist of notebooks and the expected cells to be appended to the notebook. If you’ve been using Foyle then you can produce a dataset of examples from the logs.
DATA_DIR=<Directory where you want to store the examples>
curl -X POST http://localhost:8877/api/foyle.logs.SessionsService/DumpExamples -H "Content-Type: application/json" -d "{\"output\": \"$DATA_DIR\"}"
This assumes you are running Foyle on the default port of 8877. If you are running Foyle on a different port you will need to adjust the URL accordingly.
Everytime you execute a cell it is logged to Foyle. Foyle turns this into an example where the input is all the cells in the notebook before the cell you executed and the output is the cell you executed. This allows us to evaluate how well Foyle does generating the executed cell given the preceding cells in the notebook.
Setup Foyle
Create a Foyle configuration with the parameters you want to test.
Create a directory to store the Foyle configuration.
make ${EXPERIMENTS_DIR}/${NAME}
Edit {EXPERIMENTS_DIR}/${NAME}/config.yaml
to set the parameters you want to test; e.g.
- Assign a different port to the agent to avoid conflicting with other experiments or the production agent
- Configure the Model and Model Provider
- Configure RAG
Configure the Experiment
Create the file {$EXPERIMENTS_DIR}/${NAME}/config.yaml
kind: Experiment
apiVersion: foyle.io/v1alpha1
metadata:
name: "gpt35"
spec:
evalDir: <PATH/TO/DATA>
agentAddress: "http://localhost:<PORT>/api"
outputDB: "{$EXPERIMENTS_DIR}/${NAME}/results.sqlite"
- Set evalDir to the directory where you dumped the session to evaluation examples
- Set agentAddress to the address of the agent you want to evaluate
- Use the port you assigned to the agent in
config.yaml
- Use the port you assigned to the agent in
- Set outputDB to the path of the sqlite database to store the results in
Running the Experiment
Start an instance of the agent with the configuration you want to evaluate.
foyle serve --config=${EXPERIMENTS_DIR}/${NAME}/config.yaml
Run the experiment
foyle apply ${EXPERIMENTS_DIR}/${NAME}/experiment.yaml
Analyzing the Results
You can use sqlite to query the results.
The queries below compute the following
- The number of results in the dataset
- The number of results where an error prevented a response from being generated
- The distribution of the
cellsMatchResult
field in the results- A value of
MATCH
indicates the generated cell matches the expected cell - A value of
MISMATCH
indicates the generated cell doesn’t match the expected cell - A value of
""
(empty string) indicates no value was computed most likely because an error occurred
- A value of
# Count the total number of results
sqlite3 --header --column ${RESULTSDB} "SELECT COUNT(*) FROM results"
# Count the number of errors
sqlite3 --header --column ${RESULTSDB} "SELECT COUNT(*) FROM results WHERE json_extract(proto_json, '$.error') IS NOT NULL"
# Group results by cellsMatchResult
sqlite3 --header --column ${RESULTSDB} "SELECT json_extract(proto_json, '$.cellsMatchResult') as match_result, COUNT(*) as count FROM results GROUP BY match_result"
You can use the following query to look at the errors
sqlite3 ${RESULTSDB} "SELECT
id,
json_extract(proto_json, '$.error') as error
FROM results WHERE json_extract(proto_json, '$.error') IS NOT NULL;"
3 - Adding Assertions
Adding Level 1 Evals
- Define the Assertion in eval/assertions.go
- Update Assertor in assertor.go to include the new assertion
- Update AssertRow proto to include the new assertion
- Update toAssertionRow to include the new assertion in `As