Skip to content
Snippets Groups Projects
Commit 9c4cf1be authored by Clemens Pohle's avatar Clemens Pohle
Browse files

Improve environment usage

parent c6214cd0
No related branches found
No related tags found
1 merge request!9Cleanup folder structure and improve environment usage and README
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
from django.http import JsonResponse from django.http import JsonResponse
import requests import requests
import json import json
import os
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
OLLAMA_URL = 'http://ollama:11434/api/chat' OLLAMA_URL = os.environ.get("OLLAMA_ENDPOINT") + '/api/chat'
@csrf_exempt @csrf_exempt
def ollama_query(request): def ollama_query(request):
......
...@@ -13,7 +13,7 @@ def sparql_query(request): ...@@ -13,7 +13,7 @@ def sparql_query(request):
This function executes a SPARQL query received from the frontend and returns the results in JSON format. This function executes a SPARQL query received from the frontend and returns the results in JSON format.
The SPARQL endpoint is read from the environment variables. (set in Docker-compose) The SPARQL endpoint is read from the environment variables. (set in Docker-compose)
""" """
sparql_endpoint = 'http://fuseki:3030/data/query' sparql_endpoint = os.environ.get("SPARQL_ENDPOINT") + '/data/query'
sparql = SPARQLWrapper(sparql_endpoint) sparql = SPARQLWrapper(sparql_endpoint)
sparql.setReturnFormat(JSON) sparql.setReturnFormat(JSON)
......
...@@ -18,6 +18,7 @@ services: ...@@ -18,6 +18,7 @@ services:
- "8000:8000" - "8000:8000"
environment: environment:
- SPARQL_ENDPOINT=http://fuseki:3030 - SPARQL_ENDPOINT=http://fuseki:3030
- OLLAMA_ENDPOINT=http://ollama:11434
fuseki: fuseki:
image: secoresearch/fuseki image: secoresearch/fuseki
......
...@@ -13,18 +13,16 @@ export class BackendApiService { ...@@ -13,18 +13,16 @@ export class BackendApiService {
constructor(private http: HttpClient) { } constructor(private http: HttpClient) { }
postRequest(query: string): Observable<any> { postRequest(query: string): Observable<any> {
const url = `${this.apiUrl}/sparql?query=${query}`;
console.log('sending request to: ', url)
const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
headers.set('Access-Control-Allow-Origin', '*') headers.set('Access-Control-Allow-Origin', '*')
const body = { query: query }; const body = { query: query };
return this.http.post<any>(this.apiUrl, body, { headers: headers }); return this.http.post<any>(`${this.apiUrl}/sparql`, body, { headers: headers });
} }
requestLlamaAnswer(userQuestion: string): Observable<any> { requestLlamaAnswer(userQuestion: string): Observable<any> {
const payload = { message: userQuestion }; const payload = { message: userQuestion };
const url = `${this.apiUrl}ollama-query/`; const url = `${this.apiUrl}/ollama-query/`;
console.log('Sending request to:', url); console.log('Sending request to:', url);
console.log('Request payload:', payload); console.log('Request payload:', payload);
......
export const environment = { export const environment = {
production: false, production: false,
apiUrl: 'http://localhost:8000/' // Beispiel-URL für die Entwicklung apiUrl: 'http://localhost:8000'
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment