mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 08:38:03 -06:00
Add meta files
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
package com.ridgebotics.ridgescout.utility.ollama;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.ridgebotics.ridgescout.utility.AlertManager;
|
||||
//import com.ridgebotics.ridgescout.utility.ollama.types.Messages;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class OllamaClient {
|
||||
private static final String MODEL_KEY = "llama3";
|
||||
private static final String OLLAMA_URL_KEY = "http://199.204.135.71:11434";
|
||||
|
||||
private static final String GENERATE_PATH = "/api/generate";
|
||||
|
||||
public interface ollamaListener {
|
||||
void onResponse(String response);
|
||||
void onComplete();
|
||||
}
|
||||
|
||||
private static String promptToJson(String prompt){
|
||||
|
||||
try {
|
||||
JSONObject jobj = new JSONObject();
|
||||
jobj.put("model", "llama3");
|
||||
jobj.put("prompt", prompt);
|
||||
return jobj.toString();
|
||||
} catch (JSONException e){
|
||||
AlertManager.error(e);
|
||||
}
|
||||
return "{}";
|
||||
}
|
||||
|
||||
public static void run(String prompt, ollamaListener listener){
|
||||
// ChatRequest chatRequest = new ChatRequest(MODEL_KEY, llamaMessages.messages,true);
|
||||
|
||||
RequestBody body = RequestBody.create(promptToJson(prompt), MediaType.parse("application/json"));
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(OLLAMA_URL_KEY+GENERATE_PATH)
|
||||
.post(body)
|
||||
.build();
|
||||
|
||||
new OkHttpClient().newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||
AlertManager.error(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
||||
responseStreamer(response, listener);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static void responseStreamer(Response r, ollamaListener listener){
|
||||
String line;
|
||||
ResponseBody body = r.body();
|
||||
if(body == null)
|
||||
return;
|
||||
try {
|
||||
while ((line = body.source().readUtf8Line()) != null) {
|
||||
// System.out.println(line);
|
||||
JSONObject json = new JSONObject(line);
|
||||
|
||||
listener.onResponse(json.getString("response"));
|
||||
if(json.getBoolean("done"))
|
||||
listener.onComplete();
|
||||
}
|
||||
} catch (IOException | NumberFormatException | IllegalStateException | JSONException e) {
|
||||
// addMessage(chatResponse,fullResponse.toString(),stopButton,sendButton);
|
||||
AlertManager.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
package com.ridgebotics.ridgescout.utility.ollama;
|
||||
|
||||
import static com.ridgebotics.ridgescout.utility.DataManager.evcode;
|
||||
import static com.ridgebotics.ridgescout.utility.DataManager.event;
|
||||
import static com.ridgebotics.ridgescout.utility.DataManager.match_latest_values;
|
||||
import static com.ridgebotics.ridgescout.utility.DataManager.pit_latest_values;
|
||||
|
||||
import com.ridgebotics.ridgescout.scoutingData.ScoutingDataWriter;
|
||||
import com.ridgebotics.ridgescout.types.data.dataType;
|
||||
import com.ridgebotics.ridgescout.types.data.intType;
|
||||
import com.ridgebotics.ridgescout.types.data.stringType;
|
||||
import com.ridgebotics.ridgescout.types.frcMatch;
|
||||
import com.ridgebotics.ridgescout.types.input.dropdownType;
|
||||
import com.ridgebotics.ridgescout.types.input.inputType;
|
||||
import com.ridgebotics.ridgescout.types.input.sliderType;
|
||||
import com.ridgebotics.ridgescout.utility.DataManager;
|
||||
import com.ridgebotics.ridgescout.utility.fileEditor;
|
||||
|
||||
public class PromptCreator {
|
||||
private static String fieldSummary(inputType field){
|
||||
String summary = field.name + ": ";
|
||||
switch (field.getInputType()){
|
||||
case DROPDOWN:
|
||||
summary += "The index of a dropdown with the possible options: [" +String.join(", ", ((dropdownType) field).text_options) + "]";
|
||||
break;
|
||||
case SLIDER:
|
||||
sliderType slider = (sliderType) field;
|
||||
summary += "A slider with the range ["+slider.min+","+slider.max+"]";
|
||||
break;
|
||||
case TALLY:
|
||||
summary += "A tally counter";
|
||||
break;
|
||||
case NOTES_INPUT:
|
||||
summary += "Raw text input";
|
||||
break;
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
public static String genMatchPrompt(int matchIndex){
|
||||
String prompt = "Below is a list of data collected from an FRC match. Generate a qualitative and concise summary of the teams listed, using both numerical and textual data collected in the summary. Additionally, rank the teams in order of their performance.\n\n";
|
||||
|
||||
frcMatch curmatch = event.matches.get(matchIndex);
|
||||
|
||||
prompt += "## Pit scouting\n"; prompt += "This is a list of the different fields that are present in the pit scouting data:\n";
|
||||
|
||||
for(int i = 0; i < pit_latest_values.length; i++){
|
||||
prompt += (i+1) + ") " + fieldSummary(pit_latest_values[i]) + "\n";
|
||||
}
|
||||
prompt += ("\nData:\n");
|
||||
|
||||
for(int a = 0; a < 6; a++){
|
||||
int teamNum = 0;
|
||||
if(a < 3)
|
||||
teamNum = curmatch.redAlliance[a];
|
||||
else
|
||||
teamNum = curmatch.blueAlliance[a-3];
|
||||
|
||||
prompt += "\nTeam " + teamNum + " pit scout data:\n";
|
||||
|
||||
String filename = evcode+"-"+teamNum+".pitscoutdata";
|
||||
|
||||
if (!fileEditor.fileExist(filename)) continue;
|
||||
|
||||
ScoutingDataWriter.ParsedScoutingDataResult psdr = ScoutingDataWriter.load(filename, DataManager.pit_values, DataManager.pit_transferValues);
|
||||
dataType[] types = psdr.data.array;
|
||||
for(int i = 0; i < types.length; i++) {
|
||||
boolean isNull = true;
|
||||
switch (types[i].getValueType()){
|
||||
case NUM:
|
||||
isNull = intType.isNull((int) types[i].get());
|
||||
break;
|
||||
case STRING:
|
||||
isNull = stringType.isNull((String) types[i].get());
|
||||
break;
|
||||
}
|
||||
if(isNull){
|
||||
prompt += match_latest_values[i].name + ": null\n";
|
||||
}else{
|
||||
prompt += match_latest_values[i].name + ": " + types[i].get() + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prompt += "\n## Match scouting\n";
|
||||
prompt += "This is a list of the different fields that are present in the match scouting data:\n";
|
||||
|
||||
for(int i = 0; i < match_latest_values.length; i++){
|
||||
prompt += (i+1) + ") " + fieldSummary(match_latest_values[i]) + "\n";
|
||||
}
|
||||
|
||||
prompt += ("\nData:\n");
|
||||
|
||||
for(int a = 0; a < 6; a++){
|
||||
int teamNum = 0;
|
||||
if(a < 3)
|
||||
teamNum = curmatch.redAlliance[a];
|
||||
else
|
||||
teamNum = curmatch.blueAlliance[a-3];
|
||||
|
||||
prompt += "\nTeam " + teamNum + " Match scout data for match " + curmatch.matchIndex +":\n";
|
||||
|
||||
frcMatch[] matchNums = event.getTeamMatches(teamNum);
|
||||
|
||||
for(int b = 0; b < matchNums.length; b++) {
|
||||
frcMatch match = matchNums[b];
|
||||
|
||||
String alliance = "";
|
||||
int alliancePos = 0;
|
||||
|
||||
for(int c = 0; c < 6; c++) {
|
||||
if(c<3){
|
||||
if(match.redAlliance[c] != teamNum) continue;
|
||||
alliance = "red";
|
||||
alliancePos = c+1;
|
||||
break;
|
||||
}else{
|
||||
if(match.blueAlliance[c-3] != teamNum) continue;
|
||||
alliance = "blue";
|
||||
alliancePos = c-2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String filename = evcode + "-" + match.matchIndex + "-" + alliance + "-" + alliancePos + "-" + teamNum + ".matchscoutdata";
|
||||
|
||||
if (!fileEditor.fileExist(filename)) continue;
|
||||
|
||||
ScoutingDataWriter.ParsedScoutingDataResult psdr = ScoutingDataWriter.load(filename, DataManager.match_values, DataManager.match_transferValues);
|
||||
dataType[] types = psdr.data.array;
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
boolean isNull = true;
|
||||
switch (types[i].getValueType()){
|
||||
case NUM:
|
||||
isNull = intType.isNull((int) types[i].get());
|
||||
break;
|
||||
case STRING:
|
||||
isNull = stringType.isNull((String) types[i].get());
|
||||
break;
|
||||
}
|
||||
if(isNull){
|
||||
prompt += match_latest_values[i].name + ": null\n";
|
||||
}else{
|
||||
prompt += match_latest_values[i].name + ": " + types[i].get() + "\n";
|
||||
}
|
||||
}
|
||||
prompt += "\n";
|
||||
}
|
||||
}
|
||||
return prompt;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ public class settingsManager {
|
||||
public static final String BtUUIDKey = "bt_uuid";
|
||||
public static final String FTPEnabled = "ftp_enabled";
|
||||
public static final String FTPServer = "ftp_server";
|
||||
public static final String FTPSendMetaFiles = "ftp_send_meta_files";
|
||||
|
||||
public static Map defaults = getDefaults();
|
||||
private static Map getDefaults(){
|
||||
@@ -36,6 +37,7 @@ public class settingsManager {
|
||||
hm.put(BtUUIDKey, UUID.randomUUID().toString());
|
||||
hm.put(FTPEnabled, false);
|
||||
hm.put(FTPServer, "0.0.0.0");
|
||||
hm.put(FTPSendMetaFiles, false);
|
||||
|
||||
return hm;
|
||||
}
|
||||
@@ -57,8 +59,9 @@ public class settingsManager {
|
||||
|
||||
getEditor() .putString(BtUUIDKey, (String) defaults.get( BtUUIDKey )).apply();
|
||||
|
||||
getEditor().putBoolean(FTPEnabled, (boolean) defaults.get(FTPEnabled )).apply();
|
||||
getEditor() .putString(FTPServer, (String) defaults.get( BtUUIDKey )).apply();
|
||||
getEditor().putBoolean(FTPEnabled, (boolean) defaults.get( FTPEnabled )).apply();
|
||||
getEditor() .putString(FTPServer, (String) defaults.get( FTPServer )).apply();
|
||||
getEditor().putBoolean(FTPSendMetaFiles, (boolean) defaults.get( FTPSendMetaFiles )).apply();
|
||||
}
|
||||
|
||||
// IDK why I decided to format these functions like this. It looks cool though.
|
||||
@@ -94,6 +97,9 @@ public class settingsManager {
|
||||
public static String getFTPServer(){return prefs.getString( FTPServer, (String) defaults.get(FTPServer));}
|
||||
public static void setFTPServer(String str){ getEditor().putString( FTPServer,str).apply();}
|
||||
|
||||
public static boolean getFTPSendMetaFiles(){return prefs.getBoolean(FTPServer, (boolean) defaults.get(FTPServer));}
|
||||
public static void setFTPSendMetaFiles(String str){getEditor().putString(FTPServer,str).apply();}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user