-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add hub settings + prepare for generation 2
- set generation, query_level for hub - move many files to prepare for generation 2 - teacher can set default generation for new hubs - clean up sql views - add sql.ai view but only for "sponsors"
- Loading branch information
Showing
1,670 changed files
with
879 additions
and
1,870 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -15,7 +15,8 @@ APP_MAINTENANCE_STORE=database | |
|
||
APP_COPYRIGHT=wi-wissen.de | ||
|
||
DOC_URL=https://wi-wissen.github.io/instahub-doc-de/ | ||
HUB_DEFAULT_GENERATION=1 | ||
HUB_DOC_1_URL=https://wi-wissen.github.io/instahub-doc-de/ | ||
|
||
BCRYPT_ROUNDS=12 | ||
|
||
|
@@ -55,6 +56,11 @@ MAIL_ENCRYPTION=null | |
MAIL_FROM_ADDRESS="[email protected]" | ||
MAIL_FROM_NAME="${APP_NAME}" | ||
|
||
AZURE_RESOURCE_NAME= | ||
AZURE_DEPLOYMENT_ID= | ||
AZURE_OPENAI_KEY= | ||
AZURE_VERSION=2024-02-01 | ||
|
||
VITE_APP_NAME="${APP_NAME}" | ||
|
||
WORD=achatgrau,ahornrot,agavengruen,alaskagrau,alpinaweiss,altrosa,aluminiumgrau,amarant,amarantrot,amazonasgruen,ameisenrot,ananasgelb,anthrazit,anthrazitgrau,antikgelb,antikrot,antiktuerkis,antikweiss,apfelgruen,aquamarin,aquamarinblau,asphaltgrau,atlantikblau,atlantisblau,azorenblau,azurblau,ballettrosa,bananengelb,basaltgrau,beige,beigerot,betongrau,birkengruen,blattgruen,blau,bleigrau,bluescreenblau,blutorange,blutrot,braun,braunbeige,braunrot,brillantblau,brombeerrot,bronze,burgunderrot,cappuccino,capriblau,carrerarot,cayennerot,cherry,chromgelb,creepergruen,cremeweiss,currygelb,cyan,dahliengelb,delphinblau,diamantblau,diamantgruen,diamantrot,diamantschwarz,dunkelblau,dunkelbraun,dunkelgelb,dunkelgrau,dunkelgruen,dunkellila,dunkelrosa,dunkelrot,eisblau,eisengrau,elefantengrau,elfenbein,enzianblau,erdbeerrot,erikarot,espressobraun,estorilblau,farblos,farngruen,fehengrau,fenstergrau,feuerrot,flamingorosa,flamingorot,flaschengruen,flieder,froschgruen,fruehlingsgruen,fuchsienrot,gelb,gelbgruen,gelblich,gelborange,geraniumrot,giftgruen,gilblich,ginstergelb,gletscherblau,gold,goldbraun,golden,goldgelb,granitgrau,graphitgrau,grasgruen,grau,graubeige,gruen,gruenbeige,gruenlich,guelden,haselnussbraun,heidelbeerblau,hellblau,hellbraun,hellelfenbein,hellgelb,hellgrau,hellgruen,hellrosa,hellrot,hellrotorange,himbeerrot,himmelblau,honiggelb,hummerrot,indianerrot,indigo,indigoblau,indigorot,indischgelb,indischrot,infernorot,inkarnat,italienischrot,jadegruen,jerichorot,johannisbeerrot,kadmiumgelb,kaffeebraun,kamillengelb,kanariengelb,karamellbraun,kardinalrot,karibikblau,karminrot,karminrot,kastanienbraun,kieferngruen,kieselgrau,kirschrot,kiwigruen,khakigrau,khakigruen,kobaltblau,kobaltgruen,koenigsblau,korallenrosa,korallenrot,kornblumenblau,koronagelb,kosmosschwarz,kupferrot,lachsorange,lachsrosa,lachsrot,laubgruen,lavendelblau,lehmbraun,lemongruen,leuchtgelb,leuchthellorange,leuchthellrot,leuchtorange,leuchtrot,lichtblau,lila,limonengruen,lindgruen,lotusrot,magenta,magnolienrosa,magnolienrot,mahagonibraun,mahagonirot,maigruen,maisgelb,marmor,mandelbraun,marineblau,mauritiusblau,mausgrau,meeresgruen,melonengelb,mintgruen,mohnrot,moosgrau,moosgruen,nachtblau,narzissengelb,neapelgelb,neonblau,neongelb,neongruen,neonlila,neonorange,neonpink,neonrosa,neonrot,neontuerkis,neonviolett,nougatbraun,nussbraun,ocker,ockerbraun,ockergelb,ockerrot,olivgelb,olivgrau,olivgruen,orange,orangegelb,orangerot,orchidee,orientrot,oxidrot,ozeanblau,papageirot,paprikarot,papyrus,papyrusweiss,pastell,pastellgelb,pastellorange,patinagruen,pazifikblau,pechrabenschwarz,perlbeige,perlgold,perlgrau,perlorange,perlrosa,perlrubinrot,perlweiss,permamentrosa,permamentrot,persischrot,petrol,pfirsichrot,pigmentgruen,pink,pistaziengruen,platingrau,plazentarot,porzellanblau,pflaumenblau,pumucklrot,purpur,purpurlila,purpurrot,quarzgrau,quittegelb,quittengelb,rapsgelb,rehbraun,reinorange,reinrot,resedagruen,rhabarberrot,rindenbraun,ringelblumengelb,rosa,rosenrosa,rosenrot,rosig,rostbraun,rostrot,rot,rotorange,royalblau,rubinrot,safrangelb,safranrot,saharagelb,sandgelb,sandgelb,sandsteinrot,saphirblau,scharlachrot,schiefergrau,schilfgruen,schneeweiss,schokoladenbraun,schwarz,schwarzbraun,schwarzrot,schwefelgelb,seegruen,seidengrau,sepiabraun,siena,sienabraun,signalgelb,signalorange,signalrot,silber,silbergrau,silbrig,smalteblau,smaragdgruen,sonnengelb,stahlblau,staubgrau,suedseeblau,steingrau,tabakbraun,tannengruen,taubenblau,terrabraun,terracotta,tieforange,tiefschwarz,tintenblau,tintenrot,tintenschwarz,titangrau,tizianrot,tomatenrot,torfbraun,tumblau,tuerkis,tuerkischrot,umbra,universalblau,ultramarinblau,veilchenblau,venezianischrot,violett,walnussbraun,wasserblau,weinrot,weiss,wiesengruen,wuestenrot,xenon,zartgruen,zartrosa,zeltgrau,zementgrau,ziegelrot,zimtbraun,zinkgelb,zinnoberrot,zitronengelb,zitrusgelb,zyan | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,150 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Admin; | ||
|
||
use Livewire\Component; | ||
use Illuminate\Database\QueryException; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
use OpenAI; | ||
use Throwable; | ||
|
||
class SqlAi extends Component | ||
{ | ||
public $prompt = ''; | ||
public $query = ''; | ||
public $result = ''; | ||
public $tables = ''; | ||
public $message = null; | ||
public $results = []; | ||
|
||
public function mount() | ||
{ | ||
$this->prompt = session('last_prompt', ''); | ||
$this->loadTables(); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.admin.sql-ai'); | ||
} | ||
|
||
public function runQuery() | ||
{ | ||
$this->result = ''; | ||
$this->message = null; | ||
|
||
if(! $this->prompt) { | ||
return; | ||
} | ||
|
||
try { | ||
$client = OpenAI::factory() | ||
->withBaseUri(config('azure.resource_name').'.openai.azure.com/openai/deployments/'.config('azure.deployment_id')) | ||
->withHttpHeader('api-key', config('azure.openai_key')) | ||
->withQueryParam('api-version', config('azure.api_version')) | ||
->make(); | ||
|
||
$result = $client->chat()->create([ | ||
'messages' => [ | ||
['role' => 'system', 'content' => $this->buildSystemPrompt()], | ||
['role' => 'user', 'content' => $this->prompt], | ||
], | ||
'max_tokens' => 100, | ||
]); | ||
|
||
$this->query = $this->extractSQL($result->choices[0]->message->content); | ||
|
||
if($this->query == 'UNKNOWN') { | ||
$this->message = [ | ||
'type' => 'danger', | ||
'text' => __('The input cannot be implemented with a database query.'), | ||
]; | ||
|
||
return; | ||
} | ||
} catch (Throwable $e) { | ||
$this->message = [ | ||
'type' => 'danger', | ||
'text' => (config('app.debug')) ? $e->getMessage() : __('Error in the AI query.'), | ||
]; | ||
|
||
return; | ||
} | ||
|
||
try { | ||
if (strpos(strtolower(trim($this->query)), 'select') !== 0) { | ||
DB::statement($this->query); | ||
$this->message = [ | ||
'type' => 'success', | ||
'text' => __('Query executed.'), | ||
]; | ||
} else { | ||
$this->results = DB::select($this->query); | ||
if (! $this->results) { | ||
$this->message = [ | ||
'type' => 'warning', | ||
'text' => __('Query executed. 0 results found.'), | ||
]; | ||
} else { | ||
$this->message = [ | ||
'type' => 'success', | ||
'text' => __('Query executed successfully. :count results found.', ['count' => count($this->results)]) | ||
]; | ||
} | ||
} | ||
} catch (QueryException $e) { | ||
$this->message = [ | ||
'type' => 'danger', | ||
'text' => $e->getMessage() | ||
]; | ||
} | ||
|
||
session(['last_prompt' => $this->prompt]); | ||
} | ||
|
||
private function buildSystemPrompt() | ||
{ | ||
$command = <<<'EOT' | ||
Du bist ein SQL-Generator. Du antwortest ausschließlich in gültigen SQL. | ||
Der Nutzer hat eine Aufgabe, die sich mit SQL Lösen lässt. Andernfalls schreibe nur UNKNOWN | ||
Folgende einzelne Tabellen können abgefragt werden: | ||
EOT; | ||
|
||
return $command . '\n' . $this->loadTables(); | ||
} | ||
|
||
private function loadTables() | ||
{ | ||
$r = DB::table('information_schema.tables')->where('table_schema', DB::getDatabaseName())->get(); | ||
$dbclass = ''; | ||
foreach ($r as $v) { | ||
if (!strcmp($v->TABLE_TYPE, 'BASE TABLE') && $v->TABLE_NAME != 'migrations') { | ||
$dbclass .= $v->TABLE_NAME . ': '; | ||
$columns = Schema::getColumnListing($v->TABLE_NAME); | ||
$dbclass .= implode(', ', $columns); | ||
$dbclass .= '\n'; | ||
} | ||
} | ||
$this->tables = $dbclass; | ||
} | ||
|
||
private function extractSQL($input) { | ||
// Entferne Leerzeichen am Anfang und Ende | ||
$input = trim($input); | ||
|
||
// Prüfe, ob der Input mit Markdown-Codeblock-Syntax beginnt | ||
if (preg_match('/^```sql\s*(.*?)\s*```$/s', $input, $matches)) { | ||
// Extrahiere den SQL-Code aus dem Markdown-Codeblock | ||
return trim($matches[1]); | ||
} elseif (preg_match('/^```\s*(.*?)\s*```$/s', $input, $matches)) { | ||
// Für den Fall, dass 'sql' nach '```' fehlt, aber es trotzdem ein Codeblock ist | ||
return trim($matches[1]); | ||
} else { | ||
// Wenn kein Markdown-Codeblock gefunden wurde, gib den gesamten Input zurück | ||
return $input; | ||
} | ||
} | ||
} |
Oops, something went wrong.