From 111e371dad23b9dbde435195e19829a1e2ac3175 Mon Sep 17 00:00:00 2001 From: Lasse Studion Date: Thu, 30 May 2024 13:07:46 +0200 Subject: [PATCH] feat: Add script to fetch documents and generate arguments related to electric cars This commit adds a new script, `example_fetch_docs.py`, which fetches documents from the ArangoDB database. The script uses the Ollama library to generate arguments related to electric cars from the fetched documents. The script first queries the database to retrieve documents where the translation contains the phrase "electric car". It then iterates through the fetched documents and generates arguments using the Ollama library. The generated arguments are based on a prompt that asks for arguments related to electric cars in the text of each document. The prompt is customized to provide a transcript of a speech given in the European Parliament. This script will be useful for extracting arguments related to electric cars from a collection of documents. --- example_fetch_docs.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 example_fetch_docs.py diff --git a/example_fetch_docs.py b/example_fetch_docs.py new file mode 100644 index 0000000..ffb1d2b --- /dev/null +++ b/example_fetch_docs.py @@ -0,0 +1,24 @@ +# Example of fetching documents and go though them one by one using Ollama: + +from arango import ArangoClient +import ollama +from arango_ev_class import ArangoDB + + +# Get the documents where "electric car" is mentioned +arango = ArangoDB() +db = arango.db +q = 'FOR doc IN speeches FILTER doc.translation LIKE "%electric car%" RETURN doc' +cursor = db.aql.execute(q) # Modify query +documents = list(cursor) + + +# Go though the documents one by one +for doc in documents: + text = doc['translation'] + prompt =f"""Below is a transcript of a speech given in the European Parliament. I'm interested in all arguments related to electric cars. + \n{text}\n + Please give me a list of all arguments related to electric cars in the text above. One argument per line. +Answer ONLY with the arguments. Kepp to the information in the text.""" #TODO Make a better prompt! + + arguments = ollama.generate(prompt=prompt, model='llama3:8b-instruct-q5_K_M', options={'temperature': 0})